I am having immense difficulty using a session variable through an AJAX request. The hierarchy is:
i. index.php
require_once('config.php');
<script class="include" type="text/javascript" src="js/jquery.manage.js"></script>
ii. config.php
session_start();
$loggedInUser = $_SESSION["user"];
iii. manage.js
$.post('functions.php', 'checkPermissions', function(data){});
iv. functions.php
checkPermissions(){
if ($loggedInUser->permission == "1"){
//stuff
}
}
I thought that $loggedInUser would be globalized in config.php thus accessible to functions.php. But is the problem that I am running that via an ajax request? Sometimes I feel like that means my requested PHP file is on a planet of its own and is not interacting with global PHP variables or Session variables. I get errors every variation. I've tried calling the $_SESSION variable directly in functions.php (with session_start()) but I get an error like
The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "loggedInUser" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition
$_SESSION["user"]instead of the ` $loggedInUser`?