Jump to content


Photo

file_get_contents failed to open stream


  • Please log in to reply
3 replies to this topic

#1 unemployment

unemployment

    Advanced Member

  • Members
  • PipPipPip
  • 745 posts

Posted 09 January 2012 - 10:10 AM

I am trying to use the google maps to geocode a location but I get this error:

Warning: file_get_contents(http://maps.google.c...son?address=New London,+Connecticut,+United States&sensor=false): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

$location_request 	= "http://maps.google.com/maps/api/geocode/json?address={$city},+{$real_state},+{$real_country}&sensor=false";
$geocode 	        = file_get_contents($location_request);

What am I doing wrong?  I tried URL encoding the location request but that also didn't work.


#2 Muddy_Funster

Muddy_Funster

    Advanced Member

  • Members
  • PipPipPip
  • 2,993 posts

Posted 09 January 2012 - 10:15 AM

it should work if you wrap your strings thus:
$location_request 	= "http://maps.google.com/maps/api/geocode/json?address='$city',+'$real_state',+'$real_country'&sensor=false";

A simple password hash :

function makePass($word=''){
  $dbSalt = '$2a$07$'.substr(hash('whirlpool',$word),0,22);
  $dbPass = crypt($word, $dbSalt);
 return substr($dbPass,12);
}



My SQL/PHP Blog

#3 unemployment

unemployment

    Advanced Member

  • Members
  • PipPipPip
  • 745 posts

Posted 09 January 2012 - 10:52 AM

it should work if you wrap your strings thus:

$location_request 	= "http://maps.google.com/maps/api/geocode/json?address='$city',+'$real_state',+'$real_country'&sensor=false";


It's still not working.  I get the same error.  Any other thoughts?

#4 unemployment

unemployment

    Advanced Member

  • Members
  • PipPipPip
  • 745 posts

Posted 09 January 2012 - 11:06 AM

got it.  I had to urlencode only the variables.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com