I’m developing web page which has main file index.php as follows:
include('UserClass.php');
include('html/top.php');
$user = new User();
if (isset($_POST['user'], $_POST['pass']))
{
$user->login($_POST['user'], $_POST['pass']);
}
if ($user->logged != 1)
{
include('html/forms/login.html');
include('html/forms/register.html');
include('html/calendar.php');
}
This my ajax script:
function nextMonth()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("text").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "html/calendar.php", true);
xmlhttp.send();
}
when I click button which triggers nextMonth() I got error:
Fatal error: Call to a member function check_date() on a non-object in /var/www/…/html/calendar.php on line 41
That means that object user don’t exist, so I can’t use methods from User class. Creating new instance of User inside calendar.php is not possible becouse it logouts user, whenever he try to change calndar view to next month. How should I save/pass objects from index.php when doing all this AJAX thing? Thanks!
You need the php layer to be statefull, this is done using sessions.