• 2
  • 新人请关照

Warning: session_start(): Failed to read....

<?php
class Session implements SessionHandlerInterface
{
    private $savePath;
    private $pdo;

    public function open($save_path, $session_name)
    {
        echo 'session开始<br>';
        $pdo= new PDO("mysql:host=127.0.0.1;dbname=user_info","root","");
        $this->pdo  = $pdo;
        return true;
    }

    public function close()
    {
        echo 'session结束'.'<br>';
        return true;
    }

    public function read($sess_id)
    {
        echo 'session数据被读取了<br>';
        $result = "";
        $sql = "select sess_data from `session` where sess_id = '$sess_id'";
        $stmt = $this->pdo->query($sql);
        $result = $stmt->fetch();
        $data = $result['sess_data'];
        return $data;
    }

    public function write($sess_id, $sess_data)
    {
            echo 'session数据被写入了<br>';
             $time = time();
            $sql = "replace into `session` (`sess_id`,`sess_data`,`Time`) VALUES ('$sess_id','$sess_data',$time)";
            $stmt = $this->pdo->exec($sql);
            return true;
    }

    public function destroy($sess_id)
    {
            echo '删除session'.'<br>';
            $sql = "delete  from session where sess_id = '$sess_id'";
            $stmt = $this->pdo->exec($sql);
            return true;

    }

    public function gc($maxlifetime)
    {
        echo 'session回收'.'<br>';
        return true;
    }

}

$handler = new Session();
session_set_save_handler($handler);

session_start();

出现如下错误提示:望大佬指点

image.png

阅读 439
评论
    1 个回答

    在read方法中返回序列化的数据,serialize($data)
    手册中是这样说:
    image.png

      撰写回答

      登录后参与交流、获取后续更新提醒