title: php external js only for logged in users
body: <p>I´m having a php file which checks if a user is logged in by session.</p>
  
  <pre><code>@session_start(); 
  (@$_SESSION['loggedIn'] ? '' : die(''));
  </code></pre>
  
  <p>and if so outputs a lot of JS an HTML. To keep the overview I want to exclude all JS in a file.
  My Problem is, that the JS is sending AJAX to a PHP file which querys DB content. For security reasons I want this JS only be accessible to logged in Users. Which would not be the case if I would just put it into an .js file and link to it.</p>
  
  <p>My workaround was now to put all JS code in a php file whith a Session check at the beginning followed by the JS code.</p>
  
  <pre><code>&lt;?php
  @session_start(); 
  (@$_SESSION['loggedIn'] ? '' : die(''));
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  
          jQuery(document).ready(function () {
  
      //Start configuration
          jQuery("#menu").tabify();
      ...
  </code></pre>
  
  <p>And then include this with</p>
  
  <pre><code>&lt;?php include_once('js/script.func.php');  ?&gt;
  </code></pre>
  
  <p>Is this the way you would do it, or is there are better solution? (means prevent opening security holes or errors.)</p>
  
  <p>kind regards,</p>
  
  <p>tony</p>