php curl fails whereas command line curl works php curl fails whereas command line curl works curl curl

php curl fails whereas command line curl works


I had the same problem for many (frustrating) hours. You have to replace the "&" separating your parameters with &.

The reason for why it actually worked with CLI curl (and any browser), is unknown to me: without the character escaping, the 'key' parameter doesn't seem to be sent at all and yet it makes the googlemaps api return the requested data like everything is all right ...


bad:  GET /maps/api/geocode/json?address=Salt+Lake+City%2CUT  good: GET /maps/api/geocode/json?address=Salt+Lake+City%2CUT&key=AIasasasasassahg

Obviously your are missing the key parameter in the URL.

curl_setopt($ch,CURLOPT_URL, trim($_url));

And from this code it looks like a bad $_url must be the problem.