Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last URL fetched by cURL?

Tags:

php

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?

like image 397
Googlebot Avatar asked May 17 '12 14:05

Googlebot


People also ask

How do you curl a URL?

The syntax for the curl command is as follows: curl [options] [URL...] In its simplest form, when invoked without any option, curl displays the specified resource to the standard output. The command will print the source code of the example.com homepage in your terminal window.

How do you get a redirected URL in Python?

request module. Define a web page URL, suppose this URL will be redirected when you send a request to it. Get the response object. Get the webserver returned response status code, if the code is 301 then it means the URL has been redirected permanently.

What is curl and how do you use it?

Client URL (cURL, pronounced “curl”) is a command line tool that enables data exchange between a device and a server through a terminal. Using this command line interface (CLI), a user specifies a server URL (the location where they want to send a request) and the data they want to send to that server URL.


1 Answers

You can use curl_getinfo().

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

echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
like image 161
Brad Avatar answered Oct 04 '22 10:10

Brad