Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <?php
  2. if ( isset( $_GET[ 'url' ] ) ) {
  3.  
  4. /*
  5. ** Function converting a key-index array to a string
  6. */
  7.  
  8. function arrayToString( $array, $format = '%s => %s', $delimiter = "\r\n" ) {
  9. $pieces = Array( );
  10. foreach ( $array as $key => $value ) {
  11. $pieces[ ] = sprintf( $format, $key, $value );
  12. }
  13. return implode( $delimiter, $pieces );
  14. }
  15.  
  16. /*
  17. ** Make sure the url is correct and complete it if needed
  18. */
  19.  
  20. // Get the urls
  21. $request_url = $_GET[ 'url' ];
  22. $script_url = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER['SCRIPT_NAME'];
  23.  
  24.  
  25. /*
  26. ** Take care of the information to send with the request
  27. */
  28.  
  29. // The POST data
  30. $request_content = arrayToString( $_POST, '%s=%s', '&' );
  31.  
  32. // The headers
  33. $request_headers = arrayToString( apache_request_headers( ), '%s: %s' );
  34.  
  35. // The method
  36. $request_method = $_SERVER[ 'REQUEST_METHOD' ];
  37.  
  38. // Set default context so that it is used by both get_headers( ) and file_get_contens( )
  39. $context = Array(
  40. 'content' => $request_content,
  41. 'follow_location' => false,
  42. 'header' => $request_headers,
  43. 'method' => $request_method
  44. );
  45. stream_context_get_default(
  46. Array(
  47. 'http' => $context
  48. )
  49. );
  50.  
  51. /*
  52. ** Send headers
  53. */
  54.  
  55. // Get the headers as a key-index array
  56. $response_headers = get_headers( $request_url, true );
  57.  
  58. // For each header
  59. foreach( $response_headers as $key => $value ) {
  60. if ( $key == '0' ) {// if it is the first ligne
  61. // split it to see the different parts
  62. $tmp = explode( ' ', $value );
  63. $response_version = array_shift( $tmp );
  64. $response_code = array_shift( $tmp );
  65. $response_message = implode( ' ', $tmp );
  66. // And send it
  67. header( $value );
  68. } else {// if it is a normal header
  69. if ( $key == 'Location' ) {// if it is Location
  70. // add the script url in front of it so that we continue to use the proxy
  71. $value = $script_url . '?url=' . $value;
  72. }
  73. // send the header
  74. header( $key . ': ' . $value );
  75. }
  76. }
  77.  
  78. // Add the header to allow XDR from domain
  79. header( 'Access-Control-Allow-Origin: *' );
  80.  
  81. /*
  82. ** Send content
  83. */
  84.  
  85. // if there was no error
  86. if ( $response_code == '200' ) {
  87. // output the content
  88. echo file_get_contents( $request_url );
  89. } else {
  90. print_r( $response_headers );
  91. }
  92. } else {
  93. echo 'Query string missing!';
  94. }
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement