Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter中设置cookie_Php_Codeigniter - Fatal编程技术网

Php 如何在codeigniter中设置cookie

Php 如何在codeigniter中设置cookie,php,codeigniter,Php,Codeigniter,我尝试了以下设置cookie的代码,但无法获取cookie if($this->input->post('remember')){ $this->load->helper('cookie'); $cookie = array( 'name' => 'remember_me',

我尝试了以下设置cookie的代码,但无法获取cookie

if($this->input->post('remember')){                    
                $this->load->helper('cookie');
                $cookie = array(
                        'name'   => 'remember_me',
                        'value'  => 'test',                            
                        'expire' => '300',                                                                                   
                        'secure' => TRUE
                        );
               set_cookie($cookie);                   
   }
下面的代码用于获取cookie

$cookie= get_cookie('remember_me');  
 var_dump($cookie);
谁能告诉我有什么问题吗? 提前感谢。

使用

$this->input->set_cookie($cookie);
而不是设置cookie($cookie)

使用

$this->input->set_cookie($cookie);

而不是设置cookie($cookie)

您需要创建一个控制器类并向其添加以下代码

<?php

if ( ! defined('BASEPATH')) exit('Stop Its demostrate how to set cookie');

class cw_cookies extends CI_Controller {

   function __construct()

   {

       parent::__construct();

       $this->load->helper('cookie');

   }



   function set()

   {

       $cookie= array(

           'name'   => 'remember_me',
           'value'  => 'test',                            
           'expire' => '300',                                                                                   
           'secure' => TRUE

       );

       $this->input->set_cookie($cookie);

       echo "Congratulation Cookie Set";

   }



   function get()

   {

       echo $this->input->cookie('remember_me',true);

   }

}
使用以下方法加载辅助对象:

$this->load->helper('cookie');

您可以在以下位置阅读更多内容:

您需要创建一个控制器类并向其添加以下代码

<?php

if ( ! defined('BASEPATH')) exit('Stop Its demostrate how to set cookie');

class cw_cookies extends CI_Controller {

   function __construct()

   {

       parent::__construct();

       $this->load->helper('cookie');

   }



   function set()

   {

       $cookie= array(

           'name'   => 'remember_me',
           'value'  => 'test',                            
           'expire' => '300',                                                                                   
           'secure' => TRUE

       );

       $this->input->set_cookie($cookie);

       echo "Congratulation Cookie Set";

   }



   function get()

   {

       echo $this->input->cookie('remember_me',true);

   }

}
使用以下方法加载辅助对象:

$this->load->helper('cookie');
您可以在以下网址阅读更多内容:

调用视图页面,如
echo$this->input->cookie('user')

输出=pradip

调用视图页面,如
echo$this->input->cookie('user')

输出=pradip

说数据

$my_cookie= array(

       'name'   => 'remember_me',
       'value'  => 'test value',                            
       'expire' => '3000',                                                                                   
       'secure' => TRUE

   );
使用

而不是

set_cookie($my_cookie);
说数据

$my_cookie= array(

       'name'   => 'remember_me',
       'value'  => 'test value',                            
       'expire' => '3000',                                                                                   
       'secure' => TRUE

   );
使用

而不是

set_cookie($my_cookie);

首先将这一行添加到控制器的顶部

function __construct(){
    parent::__construct();
    $this->load->helper(array('cookie', 'url'));
}
然后将cookie设置为

set_cookie('counters','ok','999600');

首先将这一行添加到控制器的顶部

function __construct(){
    parent::__construct();
    $this->load->helper(array('cookie', 'url'));
}
然后将cookie设置为

set_cookie('counters','ok','999600');

请检查CodeIgniter cookie helper,它非常简单:是否已将帮助程序加载为:
$this->load->helper('cookie')如果不这样做。。也不是
set_cookie($cookie)使用`$this->input->set\u cookie($cookie)`请检查CodeIgniter cookie helper,它非常简单:是否已将帮助程序加载为:
$this->load->helper('cookie')如果不这样做。。也不是
set_cookie($cookie)使用`$this->input->set\u cookie($cookie)`完美的干杯!干杯