2011-12-12 114 views
2

我想創建一個可以使用POST信息登錄的腳本,然後同時瀏覽所有的頁面。 (登錄後)所以我需要保持會話/ cookie的東西...PHP Curl POST/SESSION/COOKIE問題

我試過了很多事情,日誌(POST)工作正常。

但是,當我嘗試執行第二網址,(第一個是登錄頁面),我失去了會話/餅乾和它的網頁說,我不再登錄:

我要去哪裏錯了用我的代碼?

$url = 'http://www.example.com/authenticate.php'; 
$url2 = 'http://www.example.com/twourl.php'; 

$player = 'myuser'; 
$password = 'mypass'; 
$fields = array(
      'player'=>urlencode($player), 
      'password'=>urlencode($password), 
     ); 

//url-ify the data for the POST 
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
rtrim($fields_string,'&'); 

//open connection 
$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_POST,count($fields)); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

//execute post 
curl_exec($ch); 

curl_setopt($ch, CURLOPT_URL,$url2); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

//execute two url 
curl_exec($ch); 

//close connection 
curl_close($ch); 

爲什麼它不讓我登錄第二個網址?

+0

我認爲,我們需要看到您的authenticate.php代碼。 –

+0

這是一個第三方網站,所以我想我不能。 –

+0

@Steven耕作我試圖做同樣的事情,你有想過嗎?如果是這樣,你可以發佈答案嗎?謝謝 – milan

回答