title: How to read a session variable from a php file in JavaScript
body: <p>There have been far too many questions on this subject but I still fail to understand.</p>
  
  <p>Case: </p>
  
  <ol>
  <li>Hyperlinked image</li>
  <li>OnClick of image: Check if session exists</li>
  <li>If session exist, open link</li>
  <li>If session does not exist, show login form</li>
  </ol>
  
  <p><code>onclick</code> is calling a JavaScript function:</p>
  
  <pre><code>var my_global_link = '';
  var check = '&lt;?php echo $_SESSION["logged_in"]; ?&gt;';
  
  function show_login( link ) {
  
       if(check == 1)
       {
           window.location = link;
       }
       else
       {
           my_global_link = link;  
              // .. then show login modal that uses 'js/whitepaper-login.js'
              document.getElementById('light').style.display='block';
              document.getElementById('fade').style.display='block';
              document.getElementById('fade').scrollIntoView(true); 
       }
  
  }
  </code></pre>
  
  <p>Global variable is being saved in another php file as :</p>
  
  <p><code>$_SESSION['logged_in'] = 1;</code></p>
  
  <p>I am unable to capture the session value in the <code>var check</code>. Can you advise?</p>