Get session using javascript
The cookies can get by javascript if we use document.javascript.
I want to know : get session($_SESSION["session_var_name"]) by javascript () ?开发者_StackOverflow中文版????
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
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>
精彩评论