問題描述
為什么這段代碼不起作用,我怎樣才能讓它像
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!