Skip to content

Instantly share code, notes, and snippets.

@jaspervalero
Last active December 18, 2015 11:49
Show Gist options
  • Select an option

  • Save jaspervalero/5778268 to your computer and use it in GitHub Desktop.

Select an option

Save jaspervalero/5778268 to your computer and use it in GitHub Desktop.
PHP | Quick API Proxy
<?php
// Get query string
$queryString = $_SERVER['QUERY_STRING'];
// Get requested search term
$requestURL = 'https://apib4.blinkx.com/api.php?' . $queryString;
// Get XML from API
$json = callAPI( $requestURL );
header( 'Access-Control-Allow-Origin: *' );
header( 'Content-type: application/json' );
echo $json;
function callAPI( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FAILONERROR,1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION,1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER,1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 15 );
$response = curl_exec( $ch );
curl_close( $ch );
return $response;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment