Get session using javascript

Question!

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

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



Answers
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

By : Phil


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>
By : Teneff


This video can help you solving your question :)
By: admin