Kıvırmak takip yönlendirmeleri yapmak?

0 Cevap php

I'm trying to make curl follow a redirect but I can't quite get it to work right. I have a string that I want to send as a GET param to a server and get the resulting URL.


Example:
String = Kobold Vermin
Url = www.wowhead.com/search?q=Kobold+Worker

If you go to that url it will redirect you to www.wowhead.com/npc=257. I want curl to return this url to my php code so that i can extract the npc=257 and use it.


Current code:

function npcID($name) {
    $urltopost = "http://www.wowhead.com/search?q=" . $name;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
    curl_setopt($ch, CURLOPT_URL, $urltopost);
    curl_setopt($ch, CURLOPT_REFERER, "http://www.wowhead.com");
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/x-www-form-urlencoded"));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
}

Ancak bu www.wowhead.com/search?q=Kobold+Worker olup www.wowhead.com/npc=257 döndürür.

Ben dış yönlendirme gerçekleşmeden önce php dönüyor sanıyorum. Bunu nasıl düzeltebilirim?

Zaman ayırdığınız için teşekkürler.

0 Cevap