Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Last active October 2, 2020 20:49
Show Gist options
  • Save jeremyckahn/b3eeaf13af49c2586aa00fdd3e3a912f to your computer and use it in GitHub Desktop.
Save jeremyckahn/b3eeaf13af49c2586aa00fdd3e3a912f to your computer and use it in GitHub Desktop.
newsapi.org PHP proxy
<?php
header('Content-type: text/json');
header('Access-Control-Allow-Origin: *');
$url = 'https://newsapi.org/v2/top-headlines?'
. $_SERVER['QUERY_STRING']
. '&apiKey=[YOUR API KEY GOES HERE]';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
));
$result = curl_exec($curl);
curl_close($curl);
echo($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment