Welcome Guest, Not a member yet? Register   Sign In
Cookie tutorial?
#1

[eluser]Cheese[/eluser]
Just wondering if there's a tutorial on how to actually use cookies if I wanted to implement a login system. I've looked at the user guide, but all it's got is descriptions for the cookie helper functions. Then again I've never really used cookies before so the implementation for a login system is not all that apparent to me.
#2

[eluser]jedd[/eluser]
Hi Cheese and welcome to the CI forums.

There isn't (well, there might be, but I haven't seen one) but it's probably because it's such a generic / straightforward thing that only uses a handful of simple techniques.

Rather than think in terms of cookies, just think instead in terms of CI's [url="/user_guide/libraries/sessions.html"]Session functions[/url].

At login (a form, a controller, a model to do the database user/pass check) you set some session data.

You then have a function somewhere - I prefer the MY_Controller approach, but a helper would work similarly well - to identify if a user is logged in, which it does by simply checking for the presence of that bit of session data.

At logout, you unset that session data.

Easy, huh?!
#3

[eluser]Cheese[/eluser]
So this type of implementation is all Session Class based? No Cookie Helper involved? And yeah, it is definitely less complicated than I was expecting it to be.
#4

[eluser]BrianDHall[/eluser]
Login and auth systems seems like they aught to be really complicated, but they really aren't.

All you are really doing is storing a username and password, then getting it back from the user and making sure it matches something in the database.

Sessions make doing this once per 'session' really nice and easy. Manual session and cookie handling is only slightly annoying. It's one bit of magic that its really nice to allow to 'just work', and learn the details as they hit you in the head Smile
#5

[eluser]InsiteFX[/eluser]
Here is a link on using PHP Cookies will also aply to CI.

PHP Cookie Tutorials

Enjoy
InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB