【问题标题】:SessionHandlerInterface not found找不到 SessionHandlerInterface
【发布时间】:2016-06-11 13:48:34
【问题描述】:

我有这个错误:

在中未找到接口“SessionHandlerInterface” /membri/francescorizzi/php_SessionMgr/MySessionHandler.php 在第 3 行

这是我的界面代码(取自 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

【问题讨论】:

    标签: php session interface


    【解决方案1】:

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

    【讨论】:

    • 也许我解决了。我是 php 新手,如果我输入我的网址,我想通过“index.html”加载我的 php 页面:“www.site.org/main.php?...”它可以工作。如果我输入我的网址:“www.site.org/index.html?...”它会显示错误...Index.html 包含“main.php”,我的所有 php 代码都从这里开始。你能告诉我区别在哪里吗?
    • 您似乎遇到了 PHP 错误,这有点令人困惑。我会解释为什么。我假设您使用的是 Apache。通常(当我说正常时,我的意思是使用默认配置)您的服务器不应解释扩展名为 .html 的文件中的 PHP 代码。现在,我知道在某些情况下您可能希望浏览器显示 index.html 而不是 main.php。如果是这种情况,您可以简单地创建一个.htaccess 文件,其中包含以下内容RewriteRule ^index.html$ main.php [QSA,L]。这将告诉 Apache index.html 实际上是 main.php。
    • 另外,你只需要一个名为 main.php 的文件,你不需要一个实际的 index.html 文件来工作。希望有帮助。让我知道我是否应该更详细地解释它。
    • 为了让您更好地了解我的情况,我编辑了我的帖子,我尝试使用 html.it 网页并再次包含 main.php,但错误再次出现。也许我设置错了一些东西。请注意:我对 php 很陌生,我正在测试网络服务上的所有内容,这为我提供了上传我的网站和代码的可能性。除了 eclipse (php) 和 ftp 访问之外,没有 apache 知识和其他工具用于测试。 www.francescorizzi.altervista.org/index.html www.francescorizzi.altervista.org/main.php
    猜你喜欢
    • 2023-02-01
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多