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?
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.
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.
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.
You can use curl_getinfo()
.
http://php.net/manual/en/function.curl-getinfo.php
echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With