Contents
Code Description:
- Create a simple PHP Form with username ( text field ), password ( password field ), remember ( checkbox ) & Login ( submit ) button.
- If user select ‘remember’ functionality, save username & password in cookies.
- When Login Form loads, show recently saved username & password from the cookies.
Most cookies contain a unique identifier called a cookie ID: a string of characters that websites and servers associate with the browser on which the cookie is stored. Or if you sign into a website, the website might use a cookie to recognize your browser later on, so that you don’t have to sign in again.
Can you set a signed cookie for each user?
The short answer is that you shouldn’t do that. For reasons why, please see this answer. As far as what to do instead, I would set a signed cookie (that post shows how) with a large random string unique for each user. Then, when loading the session if it is new, check for the cookie. Then look up the user based on that random string.
How to save the sessionid in a cookie?
Instead, once the user has been correctly authenticated once, you could save the sessionId in a cookie and on next visit the sessionId will be passed to the server which will be able to retrieve the session. For additional security store the IP address too and check that it is the same when reopening the session.
This is stores the username if a successful login happens. When returning to the site it will fill out the username in the login form. This remembers the value of the ‘remember me’ option on the login form – true or false.
Is it safe to store password in Cookie?
You shouldn’t store the password in a cookie it’s not a good practice and can lead to security issues (somebody could “steal” the cookie for example and get the user password).