Skip to content

Instantly share code, notes, and snippets.

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 umidjons/5865318 to your computer and use it in GitHub Desktop.
Save umidjons/5865318 to your computer and use it in GitHub Desktop.
For those who use file_get_contents for JSON or other RESTful services. Site using get urls go through load balancer instead of hitting the local server. Load this function through a local url and set the Host: header for virtualhost entries on the site we wanted to load.
<?php
// set the header context stream for virtualhost lookup
$context = stream_context_create( array( 'http' => array( 'header' => 'Host: www.someurl.uz' ) ) );
// use a localhost url or alternatively 127.0.0.1 ip
$url = 'http://localhost/api/filter.org.php?login=test_user&password=mypassword&otherparam=itsvalue';
// fetch the data through webserver using the Host http header we set
$data = json_decode( file_get_contents( $url, 0, $context ) );
// verify you have your data
var_dump( $data );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment