Bonjour,
J'essaye de récupérer l'url suite à une redirection, j'ai donc trouvé un bout de script qui le fait très bien..
par contre, et pour certaine adresse, il indique la page de destination et plus l'url complète
D'avance merci pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 $url ="http://www.regeco.fr"; // va m'afficher home_news.aspx en lieu et place de http://www.regeco.fr/home_news.aspx //$url="http://www.regiepublicitaire.fr"; // new url = http://www.libbre.fr OK //$url="http://www.ne.ch"; // new url = http://www.ne.ch/Pages/accueil.aspx OK $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 if(strpos($headers[$i],"Location:") !== false){ $redir = trim(str_replace("Location:","",$headers[$i])); break; } } // do whatever you want with the result echo $redir;
Cordialement
Yule
Partager