The title is quite cryptic but essentially whats happening is I'm calling the Google Places Photo API with the following url
(I've changed my API key)
When accessing this link via the browser it redirect to a different url:
I need a way to get that second URL using PHP. Using cURL gives me a 302 "document has been moved to here" message.
Anyone know how I can get that second url via PHP?
Make your request using curl with curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
which will cause curl to follow the redirect.
Then, you can use curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
which will give you the last effective URL that curl fetched.
Alternatively, you can set CURLOPT_FOLLOWLOCATION
to false
, and set CURLOPT_HEADERS
to true
, and parse the redirect location out yourself using a simple regex.
来源:https://stackoverflow.com/questions/15297000/get-redirected-url-from-url