Googlebot
Googlebot

Reputation: 15683

How to get the last URL fetched by cURL?

If a given URL is redirected to another one, cURL will fetch the last one by

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

but how to record what was the last URL fetched by cURL?

With

curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

we do not know what was the actuall url fetched by cURL, as $link has been redirected to the final location. How to record the last location in a string?

Upvotes: 8

Views: 8290

Answers (1)

Brad
Brad

Reputation: 163438

You can use curl_getinfo().

http://php.net/manual/en/function.curl-getinfo.php

echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

Upvotes: 17

Related Questions