Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve cookie value in CodeIgniter?

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
          );

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

How can i print the above cookie?

like image 290
Roman Avatar asked Jun 20 '11 10:06

Roman


People also ask

How do you save cookies in codeigniter?

$this->input->set_cookie($cookie); In this method, only the first two parameters (name and value) are required. The expiration of the cookie is set through the expire parameter. This is the number of seconds the developer wishes to retain the cookie.


2 Answers

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);
like image 88
Repox Avatar answered Sep 21 '22 10:09

Repox


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

like image 22
Michael L Watson Avatar answered Sep 20 '22 10:09

Michael L Watson