开发者

Access Session Variable From jQuery

开发者 https://www.devze.com 2023-03-28 05:26 出处:网络
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

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

精彩评论

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