NEVER, NEVER store user data in cookies!
Here is what I suggest:
- save user id in cookie
- create a special token and hash + salt and save them in cookies.
- store everything in the database
- receive data from cookies at each page load and look for them in the database
- if not found, then log out
- change token at every page load
source share