問題描述
為什么這段代碼不起作用,我怎樣才能讓它像
Why this code not working, and how can I make it works like
setcookie('cookie_name','cookie_value');
不創(chuàng)建cookie的代碼:
$cookie=new Zend_Http_Cookie('cookie_name','cookie_value','.google.com');
或者有什么區(qū)別:
setcookie('cookie_name','cookie_value');
對(duì)比
$cookie=new Zend_Http_Cookie('cookie_name','cookie_value','.google.com');
謝謝
推薦答案
Zend_Http_Cookie 不是用來設(shè)置 cookie 的,它是 Zend_Http_Client 的配套類.假設(shè)您想從站點(diǎn)中截取一些內(nèi)容,但該內(nèi)容只有在您登錄后才可用.您可以使用 Zend_Http_Client 將您的憑據(jù)發(fā)布到登錄表單,然后服務(wù)器將發(fā)送回會(huì)話 cookie.然后,您可以在對(duì)要抓取的頁(yè)面的后續(xù)請(qǐng)求中包含此會(huì)話 cookie,以模擬登錄用戶查看該頁(yè)面.
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 中設(shè)置 cookie,您可以只使用本機(jī) PHP 函數(shù),或者可能將數(shù)據(jù)存儲(chǔ)在會(huì)話中.
To set cookies in ZF you can just use the native PHP function, or possibly store the data in the session instead.
這篇關(guān)于php setcookie vs Zend_Http_Cookie的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!