How to retrieve cookie value in CodeIgniter? How to retrieve cookie value in CodeIgniter? codeigniter codeigniter

How to retrieve cookie value in CodeIgniter?


Look at the documentation: Codeigniter Cookie Helper Guide

It says that you should use $this->input->cookie() to retrieve a cookie:

$this->input->cookie('test_cookie', TRUE);


This worked for me on localhost, security might need tightened for server

$this->load->helper('cookie');     $cookie = array(                    'name'   => 'data',                    'value'  => '23',                    'expire' =>  86500,                    'secure' => false                );                $this->input->set_cookie($cookie);                 var_dump($this->input->cookie('data', false));  

Expire needs to be numeric, removed path and set secure to false


If you are using google chrome use inspect element to see if the cookie has been set... I think you can do it in FF, but I haven't used FF in a while... I only had one issue with cookies and that was I was setting domain to my live domain... So I have my cookie code like this:

        $this->load->helper('cookie');         $cookie = array(           'name'   => 'the_cookie',           'value'  => 'test value here',           'expire' => '15000000',           'prefix' => ''        );        $this->input->set_cookie($cookie);

Here you can see it is showing up in Google Chrome "Inspect Element Tool"

Google chrome displaying the_cookie value