I use curl
to capture data from a page, but it is returning the code 301
(moved). I used CURLOPT_FOLLOWLOCATION
, but it's still the same. Does anyone know how to track the redirect?
I use curl
to capture data from a page, but it is returning the code 301
(moved). I used CURLOPT_FOLLOWLOCATION
, but it's still the same. Does anyone know how to track the redirect?
Normally such a configuration 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: link
I usually do not know if you're already doing this, use the -L option to keep track of the redirect. Otherwise access the address by the browser and after the redirect replace the URL with the new one.
curl -L <URL>