While creating my website i was stuck on a thing.
Wether i should use $_COOKIE or the session.
I thought using using $_COOKIE would be better.
But what should i store in cookie the users username or the user’s unique id ?
And how much time forward i should put the time of the cookie ?
And should i forward the same time on each page or different ? If different then how much ?
It ultimately comes down to whether your website/application needs to be stateless or not. (See Webservices are stateless?). Its mostly a design decision, but I prefer stateless applications where possible.
If you do use cookies here are some tips:
user_idor ausername(provided the user is unable to change it) and a random hash stored alongside the row in the database. When it comes to logging a user in load the user by theiruser_idand check that the hash in the cookie matches the one in the database.It is really important not to put sensitive information in cookies, because they are stored in plain text on the user’s computer.