title: Creating a PHP Session using jQuery / JS
body: <p>On page load, I want to check if a PHP Session variable exists:</p>
  
  <ul>
  <li>If it does, <code>alert()</code> the contents</li>
  <li>If it doesn't, create it and save the current time</li>
  </ul>
  
  <p>Here is my code:</p>
  
  <pre><code>$(document).ready(function(){
  
    &lt;?php if(session_id() == '') { session_start(); } ?&gt;
  
    if (!&lt;?php echo isset($_SESSION['lbBegin'])?'true':'false'; ?&gt;) {
      &lt;?php $_SESSION['lbBegin'] = date("Y-m-d H:i:s"); ?&gt;
    } else {
      alert("&lt;?php echo $_SESSION['lbBegin']; ?&gt;")
    }
  
  }); 
  </code></pre>
  
  <p>This code works in the sense that the first page load doesn't produce an <code>alert()</code> and a refresh shows the time, however every refresh / link click afterwards changes the time.  I was expecting the time to stay the same during the entire session.</p>
  
  <p>What have I done wrong?</p>