pour obtenir la dernière url redirigée dans curl de php

Salut, je sais que c'est une très sujet commun sur StackOverFlow.
J'ai déjà passé toute ma semaine pour le chercher.

J'ai une url : abc.com/default.asp?strSearch=19875379

cette nouvelle rediriger vers cette url: abc.com/default.asp?catid={170D4F36-39F9-4C48-88EB-CFC8DDF1F531}&details_type=1&itemid={49F6A281-8735-4B74-A170-B6110AF6CC2D}

J'ai fait mon effort pour obtenir la valeur finale de l'url dans mon code php à l'aide de Curl, mais ne peut pas le faire.

voici mon code:

<?php
$name="19875379";
$url = "http://www.ikea.co.il/default.asp?strSearch=".$name;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$a = curl_exec($ch);
curl_close( $ch ); 
//the returned headers
$headers = explode("\n",$a);
//if there is no redirection this will be the final url
$redir = $url;
//loop through the headers and check for a Location: str
$j = count($headers);
for($i = 0; $i < $j; $i++){
//if we find the Location header strip it and fill the redir var     
//print_r($headers);
if(strpos($headers[$i],"Location:") !== false){
        $redir = trim(str_replace("Location:","",$headers[$i]));
        break;
    }
}
//do whatever you want with the result
echo $redir;
?>

il me donne l'url "abc.com/default.asp?strSearch=19875379" au lieu de cette url "abc.com/default.asp?catid={170D4F36-39F9-4C48-88EB-CFC8DDF1F531}&details_type=1&itemid={49F6A281-8735-4B74-A170-B6110AF6CC2D}"

Merci d'avance pour votre aide 🙂

InformationsquelleAutor Avtansh | 2013-12-14