Access a url from webserver without changing php.ini
I want to access google map api for reverse geocoding. I access the url using file_get_contents method.
$url = "http://maps.google.com/maps/geo?json&ll&ll=".$lat.",".$long; $data = file_get_contents($url);And I got the value of开发者_JAVA百科 $data as FALSE, From stack overflow I got the information that its due the configuration of php.ini file (allow_url_fopen is false in our web server)
I contacted the web server people but because of security isssue they didn't ready to change the server configuration. Is there any alternate way to access the url with out changing the server configuration? Share your experiences ,knowledge ,ThanksDoes your server have the curl library installed? You could try that.
For example, you could try the following:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/2.0 (compatible; MSIE 3.02; Update a; AK; Windows 95)");
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_URL, 'http://maps.google.com/maps/geo?json&ll&ll='.$lat.','.$long );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$ret_val = curl_exec($ch);
echo $ret_val;
You can check to see if the server has the curl library installed...
http://www.php.net/manual/en/book.curl.php
You can look for something like cURL support enabled
in the output of phpinfo();
精彩评论