Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference of setcookie() and $_SESSION with session.use_only_cookies?

We can send some cookies to visitor's browser by setcookie(). When defining a value with $_SESSION['value'], if using session.use_only_cookies, the session will be only stored on the visitor's browsers. What is the difference of these two cases?

EDIT: Obviously, they are basically different. I just meant the difference in their application. We can set a value on the client-side, which can be retrieved any time (before expiration of course) with $_COOKIE or $_SESSION equally; e.g. to identify a returning visitor.

like image 327
Googlebot Avatar asked Nov 11 '11 16:11

Googlebot


People also ask

What is the difference between session () function and cookies () function in PHP?

The main difference between a session and a cookie is that session data is stored on the server, whereas cookies store data in the visitor's browser. Sessions are more secure than cookies as it is stored in server.

What is Setcookie ()?

The setcookie() function defines a cookie to be sent along with the rest of the HTTP headers. A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too.

What is the difference between session ID and cookie?

The session cookie is a server-specific cookie that cannot be passed to any machine other than the one that generated the cookie. The server creates a “session ID” which is a randomly generated number that temporarily stores the session cookie.

What is the difference between PHP cookie and PHP session?

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.


1 Answers

A cookie is stored on the client-side(i.e. "within" the client/browser).
_SESSION is serialized and then stored on the server. This data is associated with a session id. E.g. when using the default filesystem session handler the filename reflects the session id. The client (or your script) has to provide that session id in subsequent requests so that php's session management can/will load the session data again. One mechanis for this is to use cookies. session.use_only_cookies=On lets php's session mechanism look only for session ids in cookies.

like image 135
VolkerK Avatar answered Oct 12 '22 14:10

VolkerK