Created
June 26, 2013 06:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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