I am creating a PHP session using the following code:
<?php
session_start();
$_SESSION['loggedin'] = true;
?>
How can I access the variable loggedin in Javascript? In other words, I want to check in Javascript if the variable 'loggedin' is set or not.
The only way to do this is to write the value into a
scriptblock on the page as a JS variable, and reference it that way, or to make an AJAX request to a page that then returns the logged in status. There’s no way for your client to directly access the session state in any server language.