How to track Curl PHP redirect?

Asked

Viewed 732 times

0

Use the curl to capture data from a page, but is returning the code 301 (moved). I used CURLOPT_FOLLOWLOCATION, but it’s still the same. Someone knows how to track redirect?

  • 1

    Post the code of how you tried.

  • and the Curl link

  • You can also find the answer at http://answall.com/q/71275/3635 and http://answall.com/a/126095/3635

2 answers

0

Usually a setup like this is enough

// Inicia o cURL
$ch = curl_init();

curl_setopt($ch, CURLOPT_TIMEOUT, 5); // tempo em segundos
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // em segundos
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // true: permite redirecionamento
curl_setopt($ch, CURLOPT_MAXREDIRS, 1); // quantidade limite de redirecionamentos permitidos

//daqui em diante você define e outros parâmetros, etc.

See also: /a/123883/4793

-2

I don’t usually know if you’re already doing this use the -L option to track the redirect. Otherwise access the address by the browser and after the redirect replace the URL with the new one.

curl -L <URL>
  • Probably negative because the question is related to PHP, your answer is to Curl in the command line.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.