2011-05-12 45 views
2

我希望能夠將從javascript設置的cookie添加到cookie jar中。有沒有PHP的功能?或者我應該用fopen打開cookie jar並劫持它?php - 爲curl的cookiejar添加cookie

+0

咦?!你真的想使用瀏覽器端的JS來創建一個cookie,使用服務器端的PHP接收它,並存儲在一個cookie.jar文件中,以便與PHP的curl庫一起使用? – Magicianeer 2011-05-12 06:57:14

+0

@Magicianeer取決於動機是什麼。 – zaf 2011-05-12 07:13:44

+0

哦原諒我的含糊不清,但顯然,即時通過javascript和php組合曲奇設置Cookie的網站。並檢索它們時,我只能得到PHP的設置。所以我想知道如何將javascript設置cookie添加到cookie jar中。 – VeeBee 2011-05-12 08:40:06

回答

0

在記事本中打開cookie jar文件,您將看到格式保存。這是簡單的純文本格式與選項卡delemiter。

0

php_curl在它的cookie文件中預注了關於創建該文件的庫的評論,並且還包括一個指向cookie規範的鏈接。在那裏查看更多信息。

該規格相當簡單。

我知道沒有專門構建的php函數/庫來操縱cookie文件。滾動一個自定義的相當簡單。

2

正如其他人所建議的,爲了添加cookie,您必須將cookie添加到cookie jar curl屬性中提到的cookieFile中。

file_put_contents($cookie, ".ebay.com TRUE / FALSE 0 lucky9 ".$lucky9, FILE_APPEND | LOCK_EX,null); 

上面是我做的一件事,用來在我的cookie文件中插入一個cookie。

的cookieFile包含7製表符分隔的屬性一個cookie:

domain - The domain that created AND that can read the variable. 
flag - A TRUE/FALSE value indicating if all machines within a given domain can access 
the variable. This value is set automatically by the browser, depending on the value you set 
for domain. 
path - The path within the domain that the variable is valid for. 
secure - A TRUE/FALSE value indicating if a secure connection with the domain is needed  to access the variable. 
expiration - The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1, 1970 00:00:00 GMT. 
name - The name of the variable. 
value - The value of the variable. 

here.

2

無恥插頭摘自:

您可以使用Cookie Jar Writer

這是一個實用的PHP類,用於運行時編輯cURL的cookie jar文件。 換句話說,它允許在cURL請求序列內將自定義cookie變量添加到cookie文件中。