Hello everyone. Hope all is well.
I need help figuring out why my object is not persisting via sessions.. I have searched the boards and google and havent found anything useful.. take a look
#user.lib.php
require_once(LIB_SSS); #session_start() located here..
require_once(NEW_USER); #$user = & new User() here..
function ini_user(){
global $user;
if(isset($_SESSION['user'])){
#if session set get saved user..
$user = $_SESSION['user'];
}else{
#else get default user guest
$_SESSION['user'] =$user;
}
return $user;
}
#get_start - returns timestamp of when user was authenticated
#get_life - returns number of minutes before timeout
function timeout(){
global $user;
echo "time:". time() . "<br>";
echo "start:". $user->get_start() . "<br>";
echo "pass:". time() - $user->get_start() . "<br>";
echo "life:". $user->get_life()*60 . "<br><br>";
if(time() - $user->get_start() <= $user->get_life()*60){
echo "Session Timeout<br>";
}else{
echo "Session still valid". time() - $user->get_start()."<br>";
}
}
function authenticate($u,$p){
#... queries a db to populate the fields of the $user object
#and sets the start time.
}
now the driver file
#driver.php
#includes user.lib.php ..
$user = ini_user();
if($user->get_name()=="Guest"){
authenticate("user01","mypass");
echo "Authenticated..<br>";
}else{
echo "Already set<br>";
}
$user->dump();
timeout();
when I do this the timeout() function always is .. timed out because the user is always guest evertime the page is called, but
B23
it should be the authenticated user ..
any ideas? or do I need to make some clarifications..?