PHP setcookie与Zend_Http_Cookie

问题描述:

为什么此代码不起作用,如何使它像

Why this code not working, and how can I make it works like

setcookie('cookie_name','cookie_value');

不创建cookie的代码:

$cookie=new Zend_Http_Cookie('cookie_name','cookie_value','.google.com');

或者两者之间有什么区别

Or what difference between:

setcookie('cookie_name','cookie_value');

vs

$cookie=new Zend_Http_Cookie('cookie_name','cookie_value','.google.com');

谢谢

Zend_Http_Cookie不用于设置cookie,它是Zend_Http_Client的伴侣类.假设您想在网站上进行一些内容的筛选,但是该内容仅在您登录后才可用.您可以使用Zend_Http_Client将凭据发布到登录表单中,然后服务器将发送回会话cookie.然后,您可以将该会话cookie包含在对要抓取的页面的后续请求中,以模拟查看该页面的登录用户.

Zend_Http_Cookie is not for setting cookies, it is a companion class for Zend_Http_Client. Let's say you wanted to screen scape some content off a site but that content is only available if you are logged in. You could use Zend_Http_Client to post your credentials to the login form, the server would then send back a session cookie. You could then include this session cookie in a subsequent request to the page you want to scrape in order to simulate a logged in user viewing that page.

要在ZF中设置cookie,您可以仅使用本机PHP函数,也可以将数据存储在会话中.

To set cookies in ZF you can just use the native PHP function, or possibly store the data in the session instead.