2011-05-12 46 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文件中。