找不到SessionHandlerInterface

时间:2016-06-11 13:48:34

标签: php session interface

我有这个错误:

  

界面' SessionHandlerInterface'找不到   第3行/membri/francescorizzi/php_SessionMgr/MySessionHandler.php

这是我的界面代码(取自php.net作为起点):

<?php
class MySessionHandler implements SessionHandlerInterface{

private $savePath;

public function open($savePath, $sessionName)
{
    $this->savePath = $savePath;
    if (!is_dir($this->savePath)) {
        mkdir($this->savePath, 0777);
    }

    return true;
}

public function close()
{
    return true;
}

public function read($id)
{
    return (string)@file_get_contents("$this->savePath/sess_$id");
}

public function write($id, $data)
{
    return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true;
}

public function destroy($id)
{
    $file = "$this->savePath/sess_$id";
    if (file_exists($file)) {
        unlink($file);
    }

    return true;
}

public function gc($maxlifetime)
{
    foreach (glob("$this->savePath/sess_*") as $file) {
        if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
            unlink($file);
        }
    }

    return true;
}
}

我还尝试使用implements \SessionHandlerInterfaceuse SessionHandlerInterface,但这不起作用。

如何解决这个问题?

谢谢!

修改

我注意到如果我通过URL加载我的所有代码:

  

www.site.org/main.php?...

它有效,但如果我使用它:

  

www.site.org/index.html?...

错误出现了。

我的index.html页面包含main.php代码。 错误在哪里?

INDEX.HTML代码:

<html>
<body bgcolor="#000000">
<body text="grey">
<?php include('Main.php') ?>
</body>
</html>

.htaccess文件:

# # av:php5-engine
AddHandler av-php56 .php
AddType application/x-httpd-php .htm .html
RewriteRule ^index.html$ main.php

1 个答案:

答案 0 :(得分:-1)

您是否可能使用较旧的PHP版本?正如官方PHP文档中所述,SessionHandlerInterface仅在PHP 5.4.0开始时可用