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>
精彩评论