Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  96] [ 2]  / answers: 1 / hits: 130017  / 8 Years ago, fri, december 30, 2016, 12:00:00

I'm trying to create an image uploading website. In this, when a user logs in, I set a $_SESSION['id'] variable in php. Now, I wish to check if $_SESSION['id'] is set in my javascript file (general.js) in order to carry out certain functions. How should I go about doing it?


More From » php

 Answers
32
<?php $session_value=(isset($_SESSION['id']))?$_SESSION['id']:''; ?>
<html>
<head>
<script type=text/javascript>
var myvar='<?php echo $session_value;?>';
</script>
<script type=text/javascript src=general.js></script>
</head>
<body>

</body>
</html>


In above code snippet I have initialized global variable myvar with value stored into php session variable into script file before general.js file is referenced in script.It will be accessible in general.js file


[#59519] Tuesday, December 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breanab

Total Points: 731
Total Questions: 95
Total Answers: 79

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;