Codeigniter Cookie不起作用

时间:2015-03-21 19:26:03

标签: php codeigniter cookies

我使用codeigniter 2.2.0,我想设置cookie并在另一个控制器中获取它!但它没有得到饼干! 我设置了autoload.php

$autoload['helper'] = array('url','cookie');

controller/welcom.php中的代码:

class Welcome extends CI_Controller {
    public function index()
    {
            $cookie = array(
            'name'   => 'hello',
            'value'  => 'Im content for soheil',
            'expire' => 3600
        );
        $this->input->set_cookie($cookie);
    }
}
之前

anfd我在config/config.php中设置了这个值:

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "localhost";
$config['cookie_path']      = "/ci2.2/"; 
$config['cookie_secure']    = TRUE;
<{1}}和localhost

: 我已经创建了一个普通的php cookie,在Firefox中我发现了这个信息!虽然我用这段代码测试了它:

/ci2.2/

在我打开$config['cookie_prefix'] = ""; $config['cookie_domain'] = ""; $config['cookie_path'] = ""; $config['cookie_secure'] = TRUE; 页面后,我可以看到cookie已经创建了我的firefox cookie,但是当我想通过此代码在另一个控制器中通过此代码获取它时:

welcome

它返回class Soheil extends CI_Controller { public function index() { echo 'coolie is : '.$this->input->cookie('hello'); } } ,而我看到cookie是在firefox中设置的:

NULL

我读过这个问题: Why doesn't cookie work in CodeIgniter?   - Setting cookies not working in CodeIgniter - Cookie not working with Login System CodeIgniter

但我仍有问题

0 个答案:

没有答案