Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding out where curl was redirected

I'm using curl to make php send an http request to some website somewhere and have set CURLOPT_FOLLOWLOCATION to 1 so that it follows redirects. How then, can I find out where it was eventually redirected?

like image 709
John Avatar asked Nov 06 '09 14:11

John


People also ask

How do you check redirection in curl?

To follow redirect with Curl, use the -L or --location command-line option. This flag tells Curl to resend the request to the new address. When you send a POST request, and the server responds with one of the codes 301, 302, or 303, Curl will make the subsequent request using the GET method.

How do I view all URL redirections in Chrome?

Right-click on the page that is generating the redirect and choose "Inspect Element." Chrome opens a pane at the bottom of the browser window that shows all of the HTML code from the site. Scroll up to "<head>" in the Element Inspector and click the arrow next to it to expand the information.

How do I find my 301 redirect?

Simply head to Analytics and follow this path: HTTP Codes, Top Charts, HTTP Status Codes Distribution or Insights, and then click 301 URLs in the pie chart. There are also a variety of other ways you can navigate to your 301s within Analytics and URL Explorer.


2 Answers

You can do something like:

curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // returns the last effective URL
like image 191
Alix Axel Avatar answered Sep 26 '22 03:09

Alix Axel


$ch = curl_init( "http://websitethatredirects.com" );
$curlParams = array(
   CURLOPT_FOLLOWLOCATION => true,
);
curl_setopt_array( $ch, $curlParams );
$ret = curl_exec( $ch );
$info = curl_getinfo( $ch );
print $info['url'];

This will show you the URL that you were ultimately redirected to.

like image 45
Ian Van Ness Avatar answered Sep 24 '22 03:09

Ian Van Ness