0

The cookies can get by javascript if we use document.javascript.

I want to know : get session($_SESSION["session_var_name"]) by javascript () ?????

6
  • Only the session id is kept in the cookie Commented Aug 18, 2011 at 22:56
  • Good reply !! I have a question : Can any hacker get a session value using session id ?? Commented Aug 18, 2011 at 23:00
  • What specific entity do you need to get from the $_SESSION variable to the browser? Commented Aug 18, 2011 at 23:01
  • @David no, the value is stored on the server. A hacker could steal your session id and identify as you on a website Commented Aug 18, 2011 at 23:02
  • @Matt H : Sorry!! I did not understand your question ^^ Commented Aug 18, 2011 at 23:05

2 Answers 2

6

You can't. The data stored in the PHP $_SESSION super global is server-side only.

The cookies can get by javascript if we use document.javascript.

FYI, it's document.cookie

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

Comments

2

If you need any value from the $_SESSION array, you must pass it.

example:

<script type="text/javascript">
    var session_var_name = "<?=$_SESSION['var_name']?>";
</script>

you could also do it like this, BUT is really BAD practice:

<script type="text/javascript">
    // try this only at home :)
    var session = <?= json_encode($_SESSION) ?>;
</script>

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.