开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜