title: How to pass PHP session variable into Javascript/jQuery function?
body: <p>I have a PHP page that loads a session variable:</p>
  
  <pre><code>$user_id = $_SESSION['USER_ID'];
  </code></pre>
  
  <p>Previously, I included my Javascript/jQuery within that page, and added <code>&lt;? echo $user_id; ?&gt;</code> to set the Javascript variable:</p>
  
  <pre><code>$(document).ready(function() {
  
       $(".button").click(function() {
          var user_id = &lt;? echo $user_id; ?&gt;
          var dataString = 'user_id=' + user_id;  
          $.ajax({  
            type: "POST",  
            url: "../add_user.php",  
            data: dataString,  
          });  
          return false
       });
  
  
  });
  </code></pre>
  
  <p>However, I'd like to move my Javascript to a separate page and call the script from my PHP page:</p>
  
  <pre><code>&lt;script src="add_user.js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>If I do this, I can no longer user <code>&lt;? echo $user_id; ?&gt;</code>, so what is the best way to pass my PHP variable into the Javascript/jQuery function?</p>