minicl55

Untitled

Sep 7th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $baseUrl = 'https://kyleavalani.com/red/';
  4. $toOutput = '';
  5. if (isset($_GET['sessionCookie'])) {
  6. $_SESSION['sessionCookie'] = $_GET['sessionCookie'];
  7. }
  8. else if (!isset($_SESSION['sessionCookie'])) {
  9. $_SESSION['sessionCookie'] = '';
  10. $toOutput = '<b>WARNING:</b> No sessionCookie has been set.<br>';
  11. }
  12. if (!isset($_GET['url']) || $_GET['url'] == '') {
  13. echo 'No URL.';
  14. }
  15. else {
  16. //Get base url
  17. $index = 0;
  18. if (substr($_GET['url'], 0, 4) == 'http') {
  19. $index = 2;
  20. }
  21. $basename = explode('/', $_GET['url'])[$index];
  22.  
  23. //Set cookies
  24. $opts = array(
  25. 'http'=>array(
  26. 'method'=>"GET",
  27. 'header'=>"Accept-language: en\r\n" .
  28. "Cookie: reddit_session=".$_SESSION['sessionCookie']
  29. )
  30. );
  31. $context = stream_context_create($opts);
  32. //Make request
  33. $page = file_get_contents($_GET['url'], false, $context);
  34. if ($basename == 'i.imgur.com') {
  35. // Output just the image
  36. header("Content-type: image/png");
  37. }
  38. else {
  39. //We only want to alter the <Body>
  40. $pageArr = explode('</head>', $page);
  41. //Set all links to my page
  42. $pageArr[1] = str_replace('href="', 'href="'.$baseUrl.'?url=', $pageArr[1]);
  43. if ($basename == 'reddit.com') {
  44. //Replace /r/ with my_page/r/
  45. $pageArr[1] = str_replace('?url=/r/', '?url=https://reddit.com/r/', $pageArr[1]);
  46. }
  47. $page = implode($pageArr);
  48. }
  49. echo $toOutput.$page;
  50. }
Add Comment
Please, Sign In to add comment