Organizational Research By

Surprising Reserch Topic

how to retrieve cookie value in codeigniter

how to retrieve cookie value in codeigniter  using -'php,codeigniter,cookies,setcookie'

I can print the session values in codeigniter by print_r($this->session->userdata);
How can i print the cookies in codeigniter? I have just set a cookie:

$cookie = array(
          'name'   => 'test_cookie',
          'value'  => 'test',
          'domain' => '/',
          'secure' => TRUE


How can i print the above cookie?


asked Sep 15, 2015 by AracelisKest
0 votes

Related Hot Questions

5 Answers

0 votes

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

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

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

answered Sep 15, 2015 by EliMcLellan
0 votes

Look at the documentation:

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

$this->input->cookie('test_cookie', TRUE);
answered Sep 15, 2015 by KenGlenelgvr
0 votes

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:


         $cookie = array(
           'name'   => 'the_cookie',
           'value'  => 'test value here',
           'expire' => '15000000',
           'prefix' => ''

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

Google chrome displaying the_cookie value

answered Sep 15, 2015 by CHDOrv
0 votes

Load the cookie helper with:


Then retrieve your cooking with:

$cookieData = get_cookie("cookie_name");

Note, these are aliases to using the input class, you can also retrieve and set cookies like so:

$cookieData = $this->input->get_cookie("cookie_name");


answered Sep 15, 2015 by EHPAdaqxdnvi
0 votes

If the code mentioned below does not provide any output, then modify the application/config/config.php file and setting this:

$config['global_xss_filtering'] = TRUE;

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

else just use this it will display the value

answered Sep 15, 2015 by DenRwj