title: Passing Session Variable from PHP to JS
body: <p>I am currently using some jQuery that gets the content within a td cell.  I am then passing that content via a variable to another file.  I'm trying to figure out the best way to grab a session variable as well and seem to have hit a rut.  Below is some brief pseudo code along with my JS/jQuery.</p>
  
  <p>EDIT/UPDATE</p>
  
  <p>Correction to post below as well.  Here my ManageUsers.inc.php</p>
  
  <pre><code>&lt;?php
  // Load 404 page if file is accessed directly
  if(!defined('INCLUDE_CHECK')) die(header("HTTP/1.0 404 Not Found"));
  
  // Load 404 page if the page is accessed by Users or QA Agents
  if($_SESSION['role_id']&lt;2 or $_SESSION['role_id']==5) die(header("HTTP/1.0 404 Not Found"));
  
  ?&gt;
  &lt;script src="/resources/js/getBusinessUnit.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="../../resources/js/User.js"&gt;&lt;/script&gt;
  
  &lt;div id="main"&gt;
    &lt;div class="container"&gt;
      &lt;h1&gt;Manage Users&lt;/h1&gt;
      &lt;h2&gt;This page allows you to add and update the authorized Users&lt;/h2&gt;
    &lt;/div&gt;
  
    &lt;div class="container"&gt;
      &lt;div style="margin-left:auto; margin-right:auto; text-align:center;"&gt;
      &lt;span id="user"&gt;
      &lt;form name="insertUser" action="&lt;?php echo htmlspecialchars($_SERVER['PHP']);?&gt;" method="post"&gt;
        &lt;div style="margin-top:0px; margin-left:auto; margin-right:auto; text-align:center;"&gt;
          &lt;fieldset&gt;
            &lt;legend class="legend1"&gt;&lt;h2&gt;&amp;nbsp User Info &amp;nbsp&lt;/h2&gt;&lt;/legend&gt;
            &lt;div style="padding-top: 5px;"&gt;
              &lt;input type="text" name="uname" class="textinput1" id="uname" value="" style="width:200px;" maxlength="200" tabindex="2" placeholder="User Name" /&gt;&lt;br /&gt;
              &lt;input type="text" name="fname" class="textinput1" id="fname" value="" style="width:200px;" maxlength="100" tabindex="3" placeholder="First Name" /&gt;&lt;br /&gt;
              &lt;input type="text" name="lname" class="textinput1" id="lname" value="" style="width:200px;" maxlength="100" tabindex="4" placeholder="Last Name" /&gt;&lt;br /&gt;
              &lt;div style="float:left"&gt;&lt;input type="checkbox" name="status" id="status" value="YES"/&gt;Enabled &lt;/div&gt;
            &lt;/div&gt;
          &lt;/fieldset&gt;
          &lt;fieldset&gt;
            &lt;legend class="legend1"&gt;&lt;h2&gt;&amp;nbsp Company Info &amp;nbsp&lt;/h2&gt;&lt;/legend&gt;
            &lt;div style="padding-top: 5px;"&gt;
              &lt;div class="input-field"&gt;
                &lt;?php require $adm_pg.'selectRole'.$ext; ?&gt;
                &lt;/select&gt;
              &lt;/div&gt;
              &lt;div class="input-field"&gt;
                &lt;?php require $adm_pg.'selectBusinessUnit'.$ext; ?&gt;
              &lt;/div&gt;
                &lt;span id="DeptContainer"&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/fieldset&gt;
        &lt;/div&gt;
  
        &lt;?php require $adm_pg.'adminButtons'.$ext; ?&gt;
      &lt;/form&gt;
      &lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="container"&gt;
      &lt;?php require $adm_pg.'displayUsers.inc.php'; ?&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;?php
  require 'db/ManageUsers.db.php';
  require 'db/logAction.db.php';
  ?&gt;
  </code></pre>
  
  <p>Here is my User.js file</p>
  
  <pre><code>$(window).on('load', function() {
      $('.user').on('click', function() {
          var id = $(this).html();
      $.get("/includes/adminPages/Update_User.inc.php?selection_id=" + id, function(data) {
          $('#user').html(data);
          });
      });
  });
  </code></pre>