tags:

views:

281

answers:

4

Is it possible to set session variables from javascript?

+7  A: 

The short answer is no.

You can set cookies, but they're not quite the same.

You could also use AJAX to post back to a script on your server that will set the variables. Session variables exist only on the server.

Greg
+1  A: 

yes, if you use an ajax call to a server handler. Its probably not a safe thing to do. Why do you need to?

StingyJack
+2  A: 

session variables belongs to server-side scripting, thus javascript, being a client-side script is not able to set session variables. however, you are able to make use of ajax to set the session variable asynchronously, meaning without refreshing the page =)

Staelen
+1  A: 

the only thing related to sessions you can change with javascript would be the session identifier, since this is what the client sees. but changing that won't have any valuable effect on your session data—which is stored on the server

knittl