Created
February 10, 2016 15:33
-
-
Save viankakrisna/14cb0ba2ca3bb2b1bf64 to your computer and use it in GitHub Desktop.
PHP Proxy, enabling live AJAX JSON endpoint to use for local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$request = http_build_query($_GET); | |
$server = 'HTTP://YOURSERVERAJAXENDPOINT'; | |
function getCurrentUri(){ | |
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/'; | |
$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath)); | |
if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?')); | |
$uri = '/' . trim($uri, '/'); | |
return $uri; | |
} | |
$callback = file_get_contents($server.getCurrentUri().'?'.http_build_query($_GET), false, | |
stream_context_create( | |
array( | |
'http' => array( | |
'ignore_errors' => true | |
) | |
) | |
)); | |
header('Content-type: application/json'); | |
echo $callback; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment