2012-04-21 129 views
2

我正在爲我的網站測試cURL,並試圖使cURL「清除緩存」,以便會話cookie將被重新生成。一旦執行,我該如何使cURL「刪除cookies」?

所以我有一個index.php和一個login.php。 我使用正確的憑據進行POST索引,然後按照預期得到重定向到login.php。 然後,我嘗試「清除緩存」和cURL到login.php。 我期待得到一個302(重定向)到index.php,但我得到一個200 OK ...

我使用這些設置,試圖清除緩存:

$cookiefile = "d://cookie.txt"; 
curl_setopt($curl, CURLOPT_FRESH_CONNECT , 0); 
curl_setopt($curl, CURLOPT_COOKIESESSION, true); 
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile); 
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile); 
curl_setopt($curl, CURLOPT_FRESH_CONNECT , 1); 

謝謝!

+0

可能重複[php/curl:使用/ tmp(linux)中的CURLOPT \ _COOKIEJAR創建的Cookie)(http://stackoverflow.com/questions/8474659/php-curl-delete-cookie-created-with- curlopt-cookiejar式-TMP的Linux版) – 2016-08-21 10:21:00

回答

9

如果你想清除cookie,你應該取消鏈接文件unlink($cookiefile);並在此之後,你可以再次登錄沒有舊的cookie。

好鎖定。

0

刪除名稱爲$cookiefile的文件。