4

Is it possible to set session variables from javascript?

4 Answers 4

11

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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 =)

Comments

1

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

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.