饼干不beeing集,codeigniter [英] Cookies not beeing set, codeigniter
问题描述
我第一次尝试Cookie。不能得到它的工作。这是我的代码:
I'm trying out cookies for first time in CI. Cant get it to work. Here's my code:
class Site extends CI_Controller {
public function index(){
$this->load->view('input_view');
$this->load->helper('cookie');
$this->test();
}
public function test(){
$cookie = array(
'name' => 'Test',
'value' => 'The Value',
'expire' => '86500',
//'domain' => '.some-domain.com',
'path' => '/',
'prefix' => 'myprefix_',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
var_dump(get_cookie('Test'));
}
var_dump ...返回false。我理解它这是第一次,但应该不是真的后重新加载页面?我在Chrome的网络工具中也看不到任何测试Cookie。我需要域行吗?我googled一些,如果我明白它是可选的?如果不是,我想写什么? Localhost?在我的配置文件中,我有这个Cookie设置
var_dump... returns false. I understand it does this the first time but should'nt it be true after reloading the page? I can't see any "Test" cookie in my web tools in Chrome either. Do I need the "domain" row? I googled some and if I understood it was optional? If it isn't, what am i suppose to write there? Localhost? In my config file i have this settings for cookies
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
推荐答案
我猜你没有运行https
I'm guessing you're not running https for development.
您的Cookie上的 secure
标志会强制Cookie为仅通过HTTPS发送;
The secure
flag on your cookie forces the cookie to be sent over HTTPS only;
Secure:
If this cookie can ONLY be sent over HTTPS (SSL), set this value to true.
将其设置为false,cookie应该可以正常工作。
Set it to false, and the cookie should work.
这篇关于饼干不beeing集,codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!