nasıl ben curl çerez ayarlayabilirsiniz

2 Cevap php

i somesite sayfa açılırken ediyorum ..

but it display nothing and url address change.

i yazdınız örnek

http://localhost/sushant/EXAMPLE_ROUGH/curl.php

kıvırmak sayfa benim kodlama = olduğunu

$fp = fopen("cookie.txt", "w");

fclose($fp);

$agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0';

$ch = curl_init();

curl_setopt($ch, CURLOPT_USERAGENT, $agent);
 // 2. set the options, including the url  

curl_setopt($ch, CURLOPT_URL, "http://www.fnacspectacles.com/place-spectacle/manifestation/Grand-spectacle-LE-ROI-LION-ROI4.htm");  

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  

curl_setopt($ch, CURLOPT_HEADER, 0);  

curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
// 3. execute and fetch the resulting HTML output  

if(curl_exec($ch) === false)
{
  echo 'Curl error: ' . curl_error($ch);
}
else
  echo $output = curl_exec($ch);  

 // 4. free up the curl handle  
curl_close($ch); 

ama bu gibi url canege ..

http://localhost/aide.do?sht=_aide_cookies_

nesne bulunamadı.

nasıl bu sorunu bana yardımcı çözebilir

2 Cevap

Her iki Cookies.txt için çerezleri kaydetmek ve oradan onları okumak için çalıştığınız gibi görünüyor. Ne normalde yapardın ziyaret ilk url, sen kıvırmak bir dosyaya kaydetmek çerezleri olması. Sonra, ardından gelen istekler için, bu dosyayı kaynağı.

Ben php yönlerinden emin değilim, ama henüz varolmayan bir çerez dosyayı okumaya çalıştığınız gibi kıvırmak açıdan görünüyor.

edit: Eğer tek bir istek yapıyoruz oh, ve, hatta çerezleri gerekmez.

Javascript yönlendirmeyi neden çıktı, orada gibi görünüyor.

Yani kullanmak yerine, test amaçlı:

echo $output = curl_exec($ch);

Kullanın:

$output = curl_exec($ch);
echo strip_tags($output);

Güncelleme:

Aşağıdaki kod u pasring için ihtiyacınız olan her şey var ve çıkış değişkeni olmalıdır .. contents.htm içine içeriğini koyacağız.

if(curl_exec($ch) === false)
{
  echo 'Curl error: ' . curl_error($ch);
}
else{
  $output = curl_exec($ch);  
  $fp2 = fopen("content.htm" , "w");
  fwrite($fp2 , $output);
fclose($fp2);
}