Home > Backend Development > PHP Tutorial > PHP,session有关问题,$_SESSION 取不出数据,咋回事

PHP,session有关问题,$_SESSION 取不出数据,咋回事

WBOY
Release: 2016-06-13 12:29:48
Original
1013 people have browsed it

PHP,session问题,$_SESSION 取不出数据,怎么回事?
    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; //讲admin对象保存到session中    


 //这是文件 session.php 主要是把对象存放进session中  
 ?>
 
    require_once 'Admin.class.php';
    session_start();
    $admin = $_SESSION['class'];
    echo "

";<br>
    print_r($_SESSION); //这里主要看session文件中是否保存了对象,通过输出证明保存了     <br>
    echo "
Copy after login
";     
    echo $admin->getName();//但是这里用getName()方法却取不出相应的数据  
 //session2.php 取出session 中的文件 
?>






Array
(
    [class] => Admin Object
        (
            [name:Admin:private] => Mike
        )


)//这是session文件中保存的内容 显示Mike这个数据被保存了
不要听人家乱说
你的代码经实际执行,证明没有任何问题
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template