开发者

Access Session Variable From jQuery

1) If I have a users login details stored as sessions then how do I access this data via jQuery?

2) Are Sessions the best way to开发者_StackOverflow中文版 globally store user details so that they can be accessed via any front-end page?


You need to set a cookie with the username in it if you want jQuery to know what it is.

Alternatively, you could set up an ajax request to a php page that returns the username for the active session id.

You can also just output PHP before Javascript like this:

<script type="text/javascript">
    var username = "<?php echo htmlentities($_SESSION['username']); ?>";
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜