I searched for a solution to this problem until I found a very simple solution for accessing session variables, assuming you are using a .php file on the server side. Hope he answers part of the question:
access session value
<script type="text/javascript"> var value = <?php echo $_SESSION['key']; ?>; console.log(value); </script>
Edit: the best example below, which you can try on phpfiddle.org, under the "Code Space" tab
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <?php $_SESSION['key'] = 10; $i = $_SESSION['key']; ?> </head> <body> <p id="affichage">hello</p> <script type="text/javascript"> var value = <?php echo $i; ?>; $("#affichage").html(value); </script> </body> </html>
set session value
pass it the variable you may want. eg,
$you = 13; $_SESSION['user_id'] = $you;
This should work, "did not check."
Matthieu Nov 26 '15 at 21:50 2015-11-26 21:50
source share