Difference between session and cookies ?
In : IMCA Subject : Web Development Using PHPThe main difference between sessions and cookies in PHP is where the data is stored .
-
Cookies are stored on the user's browser , and they can see and sometimes change them. Cookies are used to keep track of small pieces of information like a username or a theme preference. They can be set to last for a certain time, even after the browser is closed.
-
Sessions , on the other hand, are stored on the server , not on the user's computer. Only a unique ID (called a session ID) is sent to the browser, usually through a cookie. This makes sessions more secure than cookies because users can’t directly access the data stored in them.
In short:
Use cookies for non-sensitive data that you don’t mind being stored on the user’s computer.
Use sessions for sensitive or temporary data that should stay secure and only accessible on the server.