Skip to content

Instantly share code, notes, and snippets.

@wpgeek922
Created February 17, 2016 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpgeek922/e053645fda940ea274c2 to your computer and use it in GitHub Desktop.
Save wpgeek922/e053645fda940ea274c2 to your computer and use it in GitHub Desktop.
Set headers in file_get_contents() for basic authorization
$strm_context = stream_context_create(array(
'http' => array(
'method' => 'GET', // GET,POST (HTTP METHODS)
'header' => "Authorization: Bearer ACCESS_TOKEN OR API_KEY\r\n"
)
));
$result = file_get_contents(SOURCE_URL, false, $strm_context);
$data = json_decode($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment