Question

In codeigniter, how do I store data in the cookies of the browser?

I am doing this

$this->session->set_userdata('above_eighteen',"1");

Is this the right way to do so, and on clearing cookies will this be unset?

Was it helpful?

Solution

As in the documentation http://ellislab.com/codeigniter/user-guide/helpers/cookie_helper.html,

set cookie:

$cookie = array(
    'name'   => 'The Cookie Name',
    'value'  => 'The Value',
    'expire' => '86500',
    'domain' => '.some-domain.com',
    'path'   => '/',
    'prefix' => 'myprefix_',
    'secure' => TRUE
);

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

get cookie:

cookie('The Cookie Name');

delete cookie:

delete_cookie("The Cookie Name");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top