Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between session and cookie in php?

Tags:

Hi I would like to know the difference between a php session and a cookie

like image 331
Md.Sakoat Hossen Avatar asked Dec 18 '10 16:12

Md.Sakoat Hossen


People also ask

What is the difference between session and cookies?

Cookies are client-side files on a local computer that hold user information. Sessions are server-side files that contain user data. Cookies end on the lifetime set by the user. When the user quits the browser or logs out of the programmed, the session is over.

What is session and cookie in PHP?

A session is a global variable stored on the server. Each session is assigned a unique id which is used to retrieve stored values. Whenever a session is created, a cookie containing the unique session id is stored on the user's computer and returned with every request to the server.

Which is better session or cookie?

Session is safer for storing user data because it can not be modified by the end-user and can only be set on the server-side. Cookies on the other hand can be hijacked because they are just stored on the browser.


1 Answers

The main difference being that session data is stored on the server, while cookie data is stored on the client. Therefore, a client can easily modify the cookie contents, but will have to work way harder to modify the session contents.

like image 86
netcoder Avatar answered Oct 29 '22 20:10

netcoder