What is a Session?
A session is all about the total time taken to complete an activity. In a computer any session begins or “user session” begins when the user logs in or gets an access to any computer, network server or any software service. The session ends when the user shuts down the computer or logs out any service. A session temporarily stores data or information that is related to the activity of the user while the system is connected. Session Cookie in the web page is for storing data or information when the user exits the web page or shuts down the internet browser.
For instance, any e-commerce website can remember your last searched products or products from your shopping cart when you come back.
What is a Cookie ?
Session Versus Cookies in PHP
- Sessions data is stored on the server.
- Session can store unlimited amount of data and information
- Session information is more secure, it can’t be accessed easily.
- By using session_destroy(), one can destroy the sessions.
- Session ends when the user shuts the browser or the computer.
- Session is always depends on cookies.
- In PHP a session starts with “session_start()”.
- A session can be unset or destroyed by the command “ session_destroy()”.
- In session a user can store as much as data he/she wants.
- A session only limits the maximum data a script can conuse at a time by default is 128MB.
- Cookies store data in the visitor’s browser.
- Cookies are bound to store a limited amount of data
- A Cookie is only allowed to store 4kb (4096bytes).
- Cookies are considered to be less secured and can be accessed easily.
- A Cookie’s end depends on the time period the user sets for it.
- Cookies are not dependent on session.
- Cookie doesn’t need to be started, it is automatically stored in the local machine.
- A cookie can’t be undone or unset.
- A Cookie has limited storage as compared to session.
- A Cookie starts with setcookie() function in PHP.