Php,session problem, $_session can not get the data, what is going on?
Class Admin {
Private $name;
Public Function SetName ($name) {
$this->name = $name;
}
Public Function GetName () {
return $this->name;
}
}
Admin.class.php
?>
Require_once ' Admin.class.php ';
Session_Start ();
$admin = new admin ();
$admin->setname ("Mike");
$_session[' class '] = $admin; Save the Admin object to the session
This is the file session.php the main object is to put objects in the session
?>
Require_once ' Admin.class.php ';
Session_Start ();
$admin = $_session[' class '];
echo "
";
Print_r ($_session); This is mainly to see if the session file is stored in the object, through the output certificate saved
echo "
";
echo $admin->getname ();//But here the GetName () method does not take the corresponding data
session2.php remove the file from the session
?>
Array
(
[Class] = Admin Object
(
[Name:Admin:private] = Mike
)
)//This is the content saved in the session file. Mike, this data is saved.
------Solution--------------------
Don't listen to others.
Your code is actually executed to prove that there are no problems.