Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change a $_SESSION variable client-side? [duplicate]

Possible Duplicate:
PHP Can a client ever set $_SESSION variables?

What I'd like to know, is whether a PHP $_SESSION variable can be changed on the client-side. If, for example, I do $_SESSION['username'] = $username; Can someone somehow change the value of my $_SESSION['username'] variable?

like image 893
George Korac Avatar asked Aug 02 '11 12:08

George Korac


People also ask

Can you change session variable PHP?

Update Session Variable in PHP To update any value stored in the session variable, start the session by calling session_start() function and then simply overwrite the vakue to update session variable.

Can session data be manipulated?

Yes,The Session can be manipulated by a user client side, first of all i suggest you to use HTTPS and not HTTP. Next you can use tokens with a limit time for each operation you do.

Can session be stored on client side?

Cookies and sessions are both vitally important since they record the data that the user has provided for a variety of purposes. Cookies and Sessions are used to store information. Cookies are only stored on the client-side machine, while sessions get stored on the client as well as the server.

Can the client access session variables?

Session variables can be accessed on the client side. For example you could check the value by calling: alert('<%=Session["RegisterId"] %>'); Anything between the "<%" and "%>" runs at the server so it will evaluate the current value of the session.


1 Answers

The contents of the SESSION superglobal cannot be changed. This lives on the server and the client has no way to access this.

However, a session id is passed to the client so that when the client contacts the server the server knows which session to use. This value could be changed (See Calums answer for preventing this See http://php.net/manual/en/session.security.php for information). Which would allow a user to use someone elses session (but not change the value of the session).

like image 107
Jim Avatar answered Oct 06 '22 00:10

Jim