Q6 What is the difference between Session and Cookie How to
Q6. What is the difference between Session and Cookie? How to set and retrieve cookies in PHP?
Solution
Sessions are server-side files that contain user information
The cookie will expire after 30 days (86400 * 30). The \"/\" means that the cookie is available in entire website (otherwise, select the directory you prefer).
We then retrieve the value of the cookie \"user\" (using the global variable $_COOKIE). We also use the isset() function to find out if the cookie is set:
| session | cookie |
| Sessions are server-side files that contain user information | Cookies are client-side files that contain user information |
| You can store as much data as you like within in sessions.The only limits you can reach is the maximum memory a script can consume at one time, which by default is 128MB. | Official MAX Cookie size is 4KB |
| Session ends when user close his browser. | Cookie ends depends on the life time you set for it. |
| In php $_SESSION super global variable is used to manage session. | In php $_COOKIE super global variable is used to manage cookie. |
