Welcome Guest, Not a member yet? Register   Sign In
Codeigniter and Cookies
#1

[eluser]sico87[/eluser]
I was hoping someone, could give some information on Cookies and Codeigniter, I have read there user guide on them so I have an understanding of how to set them, etc. What I want to know is how do I use for example if you look at the BBC website, you can drag and drop the boxes and it will remember where you placed them with out the need for you to sign up or login in etc, so I assume it is being stored in the the cookie.

On my site, I have a menu system that allows the user to choose the content that features on ‘their’ page, now I don’t want them to have to sign up or log in so I assume I could somehow store the content they requested in the cookie? Is this possible? Currently they click a link and the relevant content is pulled from the database using the ID in the URL and the ID in the database a match. Do I just save each ID that is requested? And if so how?
#2

[eluser]Ian Jones[/eluser]
Yes you can store custom cookie data with:
Code:
$userData = array('key' => 'value', 'key' => 'value');
$this->session->set_userdata($userData);

and retrieve a value with:
Code:
$this->session->userdata('key')

You could set and retrieve values in a non-expiring cookie as you suggested, but there is a limit to how much data a cookie can store (4KB). Hopefully your 'user' won't clear their cookies either...

The alternative is to store just a user ID in the cookie, then retrieve all the custom settings which match that user ID from the database. If you can't do it in the 4KB of cookie, then the database is your best bet. The database also would help you to track how users are setting up their options, which would be useful when you come to redesign.




Theme © iAndrew 2016 - Forum software by © MyBB