Récupérer une url aprés un url redirigé

cs_pebayart Messages postés 17 Date d'inscription mercredi 28 juillet 2004 Statut Membre Dernière intervention 6 février 2014 - 21 déc. 2006 à 14:44
juki_webmaster Messages postés 947 Date d'inscription mercredi 19 novembre 2003 Statut Membre Dernière intervention 5 avril 2008 - 21 déc. 2006 à 21:22
Bonjour tout le monde,

J'ai une colle, je cherche depuis plusieurs jours et je ne trouve pas.

Voilà, c'est peu être tout simple.

Admettons que $url est une url retourné par le moteur de recherche voilà lors d'une recherche, $url est une adresse de redirection fournit comme résultat par voila.

son format est du genre :

http://dh.search.ke.voila.fr/r?part=sho&url=http%3A%2F%2Fshopping.voila.fr&rurl=http%3A%2F%
2Fwww.bizrate.com%2Fgsird%3Fimp%3D11667074860062700613140%26pos%3D-1%26rf%
3Dwnd001%26target%3Dhttp%253A%252F%252Fshopping.voila.fr%252Fbuy%252Fsuperfind.
xpml%253Frf%253Dwnd001%2526keyword%253Dair&id=&ap=1&profil=voila&bhv=web_fr&
rdata=air&numa=0&lg=&salt=0793193&key=9d9b06c370cd00f2b86e871b09b1279b

cette adresse affiche bien la résultat (pour celle-ci il faut retirer  les retours à la ligne).

En rentrant cette adresse dans le navigateur il ouvre la bonne page, j'arrive même a faire un open et fgets sur $url mais moi je voudrais récupérer l'rul de la bonne page, la vraie, comment je fait ?

Merci de votre aide et bonne fête au passage.

Pierre-Emmanuel

1 réponse

juki_webmaster Messages postés 947 Date d'inscription mercredi 19 novembre 2003 Statut Membre Dernière intervention 5 avril 2008 3
21 déc. 2006 à 21:22
Salut,

Voila ce que me renvoie le serveur :

HTTP/1.1 302 Found
Date: Thu, 21 Dec 2006 20:00:20 GMT
Server: Apache/2.0.54 (Debian GNU/Linux)
Location: http://www.bizrate.com/gsird'imp=11667074860062700613140&pos=-1&rf=wnd001&target=http%3A%2F%2Fshopping.voila.fr%2Fbuy%2Fsuperfind.xpml%3Frf%3Dwnd001%26keyword%3Dair
Content-Length: 360
Connection: close
Content-Type: text/html; charset=iso-8859-1
HTTP/1.0 301 Moved Permanently
Date: Thu, 21 Dec 2006 20:00:20 GMT
Server: Apache/1.3.34 (Unix) mod_perl/1.29
P3P: policyref="http://www.bizrate.com/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
Set-Cookie: sessionid=600711178451771220; domain=.bizrate.com; path=/; expires=Fri, 22-Dec-2006 20:00:20 GMT
Set-Cookie: br=11667312207537540024300070101017845; domain=.bizrate.com; path=/; expires=Sun, 18-Dec-2016 20:00:20 GMT
Set-Cookie: _data=_time%3A%3Astart_time%3D1166731220%3Btimestamp%3D1166731220%7Ctracker%3A%3A_is_walk_in%3D0%3Bhtcnt%3D1%3Brf%3Dwnd001; domain=.bizrate.com; path=/; expires=Thu, 21-Dec-2006 21:00:20 GMT
P3P: policyref="http://www.bizrate.com/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
Location: http://shopping.voila.fr/buy/superfind.xpml?rf=wnd001&keyword=air
Content-length: 0
Connection: close
Content-Type: text/html; charset=iso8859-15
Via: 1.1 ExtRL001 (Juniper Networks Application Acceleration Platform - DX 5.1.5 1)
HTTP/1.0 302 Found
Date: Thu, 21 Dec 2006 20:00:21 GMT
Server: Apache/1.3.34 (Unix) mod_perl/1.29
P3P: policyref="http://shopping.voila.fr/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
P3P: policyref="http://shopping.voila.fr/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
Set-Cookie: sessionid=208600194141771221; domain=.voila.fr; path=/; expires=Fri, 22-Dec-2006 20:00:21 GMT
Set-Cookie: br=11667312213239760000100860000019414; domain=.voila.fr; path=/; expires=Sun, 18-Dec-2016 20:00:21 GMT
Set-Cookie: _data=_time%3A%3Astart_time%3D1166731221%3Btimestamp%3D1166731221%7Csearch_skipping%3A%3Aquery%3Dl1cid%3A%2012000000%2C%20l1prob%3A%200.885233269014861%2C%20l2cid%3A%2012040100%2C%20l2prob%3A%200.789794087409973%2C%20l3cid%3A%2010260100%2C%20l3prob%3A%200.00439188024029136%2C%20cid1%3A%200.789794087409973%2C%20cid2%3A%200.0536500997841358%2C%20cid3%3A%200.0514823086559772%2C%20cid4%3A%200.0411225222051144%2C%20cid5%3A%200.0406020320951939%2C%20%7Csearchapp%3A%3Auser_query%3Dair%7Csf_redir%3A%3Aredir_cat%3D12040100%7Ctracker%3A%3A_is_walk_in%3D0%3Bhtcnt%3D1%3Brf%3Dwnd001%3Bsearch_cid%3D0%3Bsearch_keyword%3Dair; domain=.voila.fr; path=/; expires=Thu, 21-Dec-2006 21:00:21 GMT
Location: http://shopping.voila.fr/9U--Camping_et_Randonnee_-_cat_id--12040100__keyword--air__rf--wnd001__sfsk--2
URI: http://shopping.voila.fr/9U--Camping_et_Randonnee_-_cat_id--12040100__keyword--air__rf--wnd001__sfsk--2
Connection: close
Content-Type: text/html; charset=iso8859-15
Via: 1.1 laxextrl04 (Juniper Networks Application Acceleration Platform - DX 5.1.5 1)
HTTP/1.0 302 Found
Date: Thu, 21 Dec 2006 20:00:21 GMT
Server: Apache/1.3.34 (Unix) mod_perl/1.29
P3P: policyref="http://shopping.voila.fr/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
P3P: policyref="http://shopping.voila.fr/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
Set-Cookie: sessionid=809400167201771221; domain=.voila.fr; path=/; expires=Fri, 22-Dec-2006 20:00:21 GMT
Set-Cookie: br=11667312219560230018400940000016720; domain=.voila.fr; path=/; expires=Sun, 18-Dec-2016 20:00:21 GMT
Set-Cookie: _data=_time%3A%3Astart_time%3D1166731221%3Btimestamp%3D1166731221%7Ctracker%3A%3A_is_walk_in%3D0%3Bhtcnt%3D1%3Brf%3Dwnd001%3Bsearch_cid%3D0%3Bsearch_keyword%3Dair; domain=.voila.fr; path=/; expires=Thu, 21-Dec-2006 21:00:21 GMT
Location: http://shopping.voila.fr/8B--Camping_et_Randonnee_-_cat_id--12040100__keyword--air__rf--wnd001__sfsk--2
URI: http://shopping.voila.fr/8B--Camping_et_Randonnee_-_cat_id--12040100__keyword--air__rf--wnd001__sfsk--2
Connection: close
Content-Type: text/html; charset=iso8859-15
Via: 1.1 laxextrl04 (Juniper Networks Application Acceleration Platform - DX 5.1.5 1)
HTTP/1.0 200 OK
Date: Thu, 21 Dec 2006 20:00:22 GMT
Server: Apache/1.3.34 (Unix) mod_perl/1.29
P3P: policyref="http://shopping.voila.fr/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
P3P: policyref="http://shopping.voila.fr/w3c/p3p.xml", CP="NON DSP ADM DEV PSD CUSo OUR IND STP PRE NAV UNI"
Set-Cookie: sessionid=800200263431771222; domain=.voila.fr; path=/; expires=Fri, 22-Dec-2006 20:00:22 GMT
Set-Cookie: br=11667312224780430021100020000026343; domain=.voila.fr; path=/; expires=Sun, 18-Dec-2016 20:00:22 GMT
Set-Cookie: _data=_time%3A%3Astart_time%3D1166731222%3Btimestamp%3D1166731222%7Cbug%3A%3Aattr_group%3DMarques--259%5C%7CAccessoires--623732%5C%7CArticles%20de%20randonn%E9e--623878%5C%7CR%E9chauds%20de%20camping%20et%20ustensiles--623856%5C%7CGlaci%E8res%20et%20conteneurs--360764%5C%7CSexe--256143%5C%7CGamme%20de%20prix%26%23xA0%5C%3B--259818%5C%7Cou%20parcourir%20par%7Cjs_focus%3A%3Aoverride%3D0%7Comniture%3A%3Aomniture_orig_user_source%3Dwnd001%3Bomniture_rf_code%3Dwnd001%7Ctracker%3A%3A_is_walk_in%3D0%3Bhtcnt%3D1%3Bmemetrics_send%3D1%3Bmtrcs_hostname%3Dshopping.voila.fr%3Bmy_s_nr%3D1166731223000%3Bomniture_cc%3DFR%3Bomniture_last_page%3D8B%20%3A%20Search%20Results%20-%20NonCat%3Bomniture_orig_brand%3Dvoila%3Brf%3Dwnd001%3Bsearch_cid%3D12040100%3Bsearch_keyword%3Dair; domain=.voila.fr; path=/; expires=Thu, 21-Dec-2006 21:00:23 GMT
Content-length: 112728
Connection: close
Content-Type: text/html; charset=iso8859-15
Via: 1.1 laxextrl04 (Juniper Networks Application Acceleration Platform - DX 5.1.5 1)


Dans ce cas, autant utiliser la libraire PHP-cURL.
http://fr3.php.net/curl
Et particulierement la constante CURLOPT_FOLLOWLOCATION
Puis CURLINFO_EFFECTIVE_URL sur curl_getinfo

Petit exemple que je t'es fait :

<?php
$url = 'http://dh.search.ke.voila.fr/r?part=sho&url=http%3A%2F%2Fshopping.voila.fr&rurl=http%3A%2F%2Fwww.bizrate.com%2Fgsird%3Fimp%3D11667074860062700613140%26pos%3D-1%26rf%3Dwnd001%26target%3Dhttp%253A%252F%252Fshopping.voila.fr%252Fbuy%252Fsuperfind.xpml%253Frf%253Dwnd001%2526keyword%253Dair&id=&ap=1&profil=voila&bhv=web_fr&rdata=air&numa=0&lg=&salt=0793193&key=9d9b06c370cd00f2b86e871b09b1279b';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if (curl_exec($curl)) {
var_dump(curl_getinfo($curl,CURLINFO_EFFECTIVE_URL)); // <---
}
curl_close($curl);
?>
0
Rejoignez-nous