I have a session variable called $_SESSION['SESS_USER_TYPE']
in my php file which is set to a 2 character string. The php script redirects to an HTML file where I want to get the php session variable into a javascript variable.
I am using it in my javascript as follows, but I get nothing in the javascript variable.
var user_type = <?php echo $_SESSION['SESS_USER_TYPE']; ?>;
This does not work.
Further to input received from other users, I tried the following :
var user_type = '<?php echo json_encode($_SESSION['SESS_USER_TYPE']) ?>';
Javascript returns a syntax error to the above.
I then tried
user_type = "<?php echo json_encode($_SESSION['SESS_USER_TYPE']) ?>";
This does not give an error in Javascript. However it returns the following value to user_type which is :
<?php echo json_encode($_SESSION['SESS_USER_TYPE']) ?>
$_SESSION['SESS_USER_TYPE'] is set to the string 'WO'.