I have a login page that sets up session parameters on successful login. The login page is then redirected to the admin page. The admin page can read session variables easily. But when I execute the jQuery load () function, which loads viewUsers.php in the contents of the div, the session variables have disappeared. The strange part is the session identifier.
I used var_dump () on both the admin page and the viewUsers page. All the correct variables from the login page are displayed on the admin pages, but the viewUsers page, called by the jQuery load () var_dump function in $ _SESSION, is empty. The var_dump of $ _COOKIE ['PHPSESSID'] has the correct identifier, but it makes no sense to me.
This is how I set the session variables.
$_SESSION['userID'] = $userInfo['ID']; $_SESSION['userType'] = $userInfo['userType']; $_SESSION['programID'] = $userInfo['programID'];
This is jQuery
$("#content").load("viewUsers.php");
All pages have session_start (). Session variables also did not work when I tried to use window.open and window.location instead of the jQuery load () function.
Some, like session variables, are lost, although I have the correct session id. If anyone could shed light on this, I would really appreciate it!
I am currently filling out hidden fields and using the post function instead of the load to get around it. I understand that this is not the best way, but this is the only way to understand how to do it.
Edit: Here is the top of the index that reads session variables perfectly.
<?php session_start(); //require("session.php"); if(!isset($_SESSION['userID'])){ header("location: ../login/index.php"); } ?>
Here are all viewusers
<?php session_start(); //foreach($_POST as $name => $value){ //$_SESSION[$name] = $value; //} //echo " session id " . $_COOKIE['PHPSESSID']; var_dump($_COOKIE); var_dump($_SESSION); ?> <?php require("adminFunctions.php"); ?> <h2>View Current Users</h2> <?php require("userlinks.php"); ?> <table id="userTable" class="tablesorter"> <?php getUsers($_SESSION['programID'], $_SESSION['userType']) ?> </table> <script type="text/javascript"> $('td[name="userID"]').hide(); //$("#userTable th").click(function(){ //color(); //colorTable(); //color(); //}); function colorTable(){ $("tr:odd").css("background-color", "#c0c0c0"); $("tr:even").css("background-color", "#ffffff"); } function color(){ $("tr:odd").css("background-color", "#ffffff"); $("tr:even").css("background-color", "#ffffff"); } $(document).ready(function(){ //colorTable(); $("#userTable").tablesorter({widgets: ['zebra']}); }); </script>
Other Edit: Here is the javascript code to load viewusers The only reason I use the post is that I set the session variables as hidden fields to pass the session variables. On viewusers, I use a foreach loop to set session variables. I understand that this is not safe. function maintainUsers () {
$.post("viewUsers.php", $("#sessionform").serialize(),function(data){