Hello. I have a class called User, with a constructor that loads all the variables in that class. On login, I assign a new instance of User to $_SESSION['user']:
Code: Select all
<?php
include_once("user_class.php");
//login and all that
session_start();
$_SESSION['user'] = new User;
?>
My problem start when I want to call on a function or a variable in the User class from another page. I do something along these lines:
Code: Select all
<?php
include_once("user_class.php");
session_start();
echo "Printing Started";
echo $_SESSION['user']->username; //supposed to output the username
echo "Printing Finished";
?>
Unfortunatly, the above code produces "Pring StartedPrinting Finished" with nothing in the middle. It does work however if in that same code I put in $_SESSION['user'] = new User (so the object is fine), but I don't want to create a new object on each page, hence the $_SESSION superglobal. Little help?
Thanks!