PHP setcookie与Zend_Http_Cookie [英] php setcookie vs Zend_Http_Cookie

查看:69
本文介绍了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.

这篇关于PHP setcookie与Zend_Http_Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆