Read the session data from session storage file

前端 未结 6 1620
执念已碎
执念已碎 2020-12-01 16:20

Facing problem with PHP unserialize() function as titled it is throwing error.

unserialize() [function.unserialize]: Error at offset 0 of 1781 b         


        
6条回答
  •  一个人的身影
    2020-12-01 17:01

    check out, this might click you something

    function read($filename)
    {
        session_save_path("/tmp/tst");
        session_start();
        echo    $sCurrentFile = "/tmp/tst/sess_".session_id();
        $sFileToRead = $filename;
        if( !file_exists($sFileToRead) || !$sessionData=(string)@file_get_contents($sFileToRead) )
        {
            echo "file does not exist";
        }
    
        $fh = fopen($sCurrentFile, 'w') or die("can't open file");
        fwrite($fh, $sessionData);
        fclose($fh);
        $_SESSION["mytest"] = 444; 
        print_r($_SESSION);
    }
    

提交回复
热议问题