Skip to content

Instantly share code, notes, and snippets.

@viankakrisna
Created February 10, 2016 15:33
Show Gist options
  • Save viankakrisna/14cb0ba2ca3bb2b1bf64 to your computer and use it in GitHub Desktop.
Save viankakrisna/14cb0ba2ca3bb2b1bf64 to your computer and use it in GitHub Desktop.
PHP Proxy, enabling live AJAX JSON endpoint to use for local
<?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