2012-05-09 29 views
1

正在試圖從外部頁所有Cookie,並設置他們在我的頁面上,我有這個腳本:捲曲得到外部頁面餅乾和在我的頁面使用它們

$url = "http://www.booking.com/hotel/cz/red-blue-design-prague.html?checkin=2012-07-07&interval=1&selected_currency=USD"; 
$ckfile = tempnam ("tmp", "CURLCOOKIE"); 

$options = array(
    CURLOPT_RETURNTRANSFER => TRUE,  // return web page 
    CURLOPT_HEADER   => TRUE,  // do not return headers 
    CURLOPT_HEADER   => TRUE,  // do not return headers 
    CURLOPT_FOLLOWLOCATION => TRUE,  // follow redirects 
    CURLOPT_USERAGENT  => "googlebot", // who am i 
    CURLOPT_AUTOREFERER => TRUE,  // set referer on redirect 
    CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
    CURLOPT_TIMEOUT  => 120,  // timeout on response 
    CURLOPT_MAXREDIRS  => 3,  // stop after 10 redirects 
    CURLOPT_ENCODING  => 'UTF-8', 
    CURLOPT_COOKIEJAR  => $ckfile, 
    CURLOPT_COOKIEFILE  => $ckfile 
); 
    $ch = curl_init(); 
    curl_setopt_array($ch, $options); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    $a = curl_exec($ch); 

,但它沒有得到餅乾當我檢查$ckfile,可以有人幫助,謝謝

+0

這將會是有益的,看看輸入,輸出,錯誤... – LeonardChallis

+0

@LeonardChallis沒有錯誤,做工精細,但它ñ ot得到餅乾 – mgraph

+0

該cookie文件是否包含任何內容? – LeonardChallis

回答

2

我找到了解決辦法,大家好,感謝:

function myCurl($url) 
{ 
    $cookie_file_path = tempnam ("tmp", "CURLCOOKIE"); 

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl, CURLOPT_HEADER, 0); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($curl, CURLOPT_AUTOREFERER, 0); 
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); 
    curl_setopt($curl, CURLOPT_TIMEOUT, 60); 
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file_path); 
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file_path); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE); 
    curl_setopt($curl, CURLOPT_COOKIE, session_name() . '=' . session_id()); 
    curl_setopt($curl, CURLOPT_URL, $url); 

    $a = curl_exec ($curl); 

    return $a; 
} 
+0

如果這是工作,它不再是 – Asped