2016-01-24 74 views
0

我使用githubphp-curl-classPHP cURL類 - 餅乾不起作用

我發送了幾條帖子,使用$curl->post("webiste.com", array());登錄網站,並從響應返回數據後,我可以驗證我成功登錄。

我的問題在於使用$curl->get("http://website.com");

PHP cURL類的get()函數沒有正確讀取cookie。

我的代碼包含在文檔的頂部以下內容:

$curl = new Curl(); 
$curl->setCookieFile('cookies.txt'); 
$curl->setCookieJar('cookies.txt'); 

這是不夠的get()函數來正確使用cookies嗎?

我可以驗證cookies.txt文件是否已創建,並將cookies打印在文件中,但它們只是未被100%使用。

我知道他們沒有被正確讀取,因爲當我使用下面的代碼:

echo $curl->get("website.com"); 

我可以看到,我不是在登錄

回答

0

我已經解決了這個問題。

所以我添加

$curl->setCookieFile('cookies.txt'); 
$curl->setCookieJar('cookies.txt'); 

在函數中,我試圖用

$curl->get(); 

之外的功能。我只在函數內部設置了cookiejar和cookiefile,所以在$ curl-> get();之前,函數,我需要重新聲明cookiefile & jar。