SORU
19 AĞUSTOS 2010, PERŞEMBE


Curl yönlendirmeleri takip edin?

Curl yönlendirme takip etmeye çalışıyorum ama oldukça doğru çalışması için alamadım. Bir sunucuya param OLSUN ve çıkan URL almak göndermek istiyorum bir dize var.

Örnek:

String =Kobold Haşarat
= Urlwww.wowhead.com/search?q=Kobold İşçi

Eğer bu url giderseniz sizi yönlendirir"". www.wowhead.com/npc=257 Curl "npc=257" ve kullanın. Bu özü böylece benim PHP kodu bu URL dönmek istiyorum

Geçerli kod:

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);
}

Bu ancak verirwww.wowhead.com/search?q=Kobold İşçideğilwww.wowhead.com/npc=257.

PHP dış Yönlendirme Olmadan dönüyor sanıyorum. Bu durumu nasıl düzeltebilirim?

CEVAP
19 AĞUSTOS 2010, PERŞEMBE


CURL yönlendirmesi takip etmesi için, kullanın:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Erm... curl... Deneyin aslında yürüttüğünüzü sanmıyorum:

curl_exec($ch);

...sonra ayar seçenekleri, ve daha önce curl_getinfo() arayın.

EDİT: Eğer sadece istiyorum bir sayfa yönlendirmeleri için kullanabilirsiniz, tavsiye here ve sadece Curl kullanmak için kapmak başlıkları ve Özü Konumu: başlığından onlara

$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);
if(preg_match('#Location: (.*)#', $a, $r))
 $l = trim($r[1]);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • captainpuppys2000

    captainpuppy

    20 HAZİRAN 2013
  • bored before i even began

    bored before

    30 Mart 2009
  • Slave Boy Films - Fandom from a Galaxy Far Far Away

    Slave Boy Fi

    12 HAZİRAN 2009