Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Last active October 6, 2015 15:58
Show Gist options
  • Save DimitarChristoff/3017516 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/3017516 to your computer and use it in GitHub Desktop.
<?php
/**
* proxy for getting json data via CURL
*/
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$url = $_REQUEST['url'];
// clean the url here and make sure it's valid and escaped... then:
// $url = cleanURL($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>

then simply do a local

Request.JSON({
    url: '/proxy.php?url=http://m.airpim.com/json/public/search?&k=&e=1',
    onComplete: function(data) {
        console.log(data);
    }
}).send();

to make it safer, you can just hardwire the url into the proxy and possibly append escaped search terms or whatever so these will become your only argument.

@pinoniq
Copy link

pinoniq commented Jul 25, 2013

your php script is not retruning any data at the moment. you still need an echo/print ;)

@DimitarChristoff
Copy link
Author

It was not intended to be fully functional but fair enough :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment