php setcookie vs Zend_Http_Cookie(php setcookie vs 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');
或者有什么区别:
setcookie('cookie_name','cookie_value');
对比
$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 vs Zend_Http_Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php setcookie vs Zend_Http_Cookie
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
