Php 致命错误:类';xxx和x27;找不到

Php 致命错误:类';xxx和x27;找不到,php,mysql,class,session,fatal-error,Php,Mysql,Class,Session,Fatal Error,为什么我的应用找不到会话处理程序?我得到一个错误: 致命错误:在第2行的/Users/Eamon/Sites/index.php中找不到类“Session” 编辑2(refactured index.php) 这是我的index.php: <?php class Session { private $savePath; function open($savePath, $sessionName) { $this->savePath = $savePath; if (

为什么我的应用找不到会话处理程序?我得到一个错误:

致命错误:在第2行的/Users/Eamon/Sites/index.php中找不到类“Session”

编辑2(refactured index.php)

这是我的index.php:

<?php
class Session
{
private $savePath;

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

    return true;
}

function close()
{
    return true;
}

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

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

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

    return true;
}

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

    return true;
}
}

$handler = new Session();
session_set_save_handler(
    array($handler, 'open'),
    array($handler, 'close'),
    array($handler, 'read'),
    array($handler, 'write'),
    array($handler, 'destroy'),
    array($handler, 'gc')
);

// the following prevents unexpected effects when using objects as save handlers
register_shutdown_function('session_write_close');

session_start();
// proceed to set and retrieve values by key from $_SESSION
// set time-out period (in seconds)
$inactive = 600;

// check to see if $_SESSION["timeout"] is set
if (isset($_SESSION["timeout"])) {
// calculate the session's "time to live"
$sessionTTL = time() - $_SESSION["timeout"];
if ($sessionTTL > $inactive) {
    session_destroy();
    echo "session destroyed;"
}
}
?>
<html>...<html>

<?php
session_destroy();
?>
更新2

显然

函数session\u set\u save\u处理程序需要向其传递六个参数

我在这里读到:

更新3

修复了上面的参数错误…只需将会话类直接放在我的index.php中(我更改了上面的代码以反映我在index.php中的更改)。基本上…我有你在这里的例子2中看到的-

以下是我得到的新错误:

警告:session_start()[function.session start]:无法发送会话缓存限制器-第2行的/Users/Eamon/Sites/templates/showuser.php中已发送的头(输出从/Users/Eamon/Sites/templates/showuser.php:1开始)

下面是showuser.php:

<?php
    session_start();

    $host="localhost"; // Host name
    $uname="root"; // Mysql username
    $password="bonjour3"; // Mysql password
    $db_name="itit"; // Database name
    $tbl_name="users"; // Table name

    // Connect to server and select database.
    $mysqli = mysqli_connect($host, $uname, $password, $db_name);
    $stmt = $mysqli->prepare("SELECT email FROM users WHERE username = ?");
    $stmt->bind_param("s", $_SESSION["username"]);
    $stmt->execute();
    $stmt->bind_result($em);
    $stmt->fetch();
?>

<h2>Username - Email</h2>
<div id="userinfo"><? echo $_SESSION["username"] ?> - <? echo $em ?></div>

<? 
    $stmt->close();
    mysqli_close($mysqli);
?>

用户名-电子邮件
- 

再次…检查我对index.php(session.php文件不再存在)所做的更改。

尝试
包含它

include 'session.php';

必须包含
session.php
文件才能访问其类

<?php
include "path_to_session.php";
$handler = new Session();

@yogeshuthar..修复了它-但现在我得到了
致命错误:在xxx中找不到接口“SessionHandlerInterface”
我找到了这个-。下面有一条评论说要将其添加到命名空间…我不知道这是什么意思。@ewizard您还必须包括该接口的路径。所以我需要在名为“SessionHandlerInterface.php”的文件中创建该接口?或者我可以从某个地方下载它…我的目录中没有这个文件。解决了接口问题…现在出现了一些错误…我将更新我的问题以反映我的进度。哈哈…我只是更改了我的所有代码以反映该示例中的内容…伟大的人都有同感!我消除了这个错误…不过还有一个错误…
警告:session_start()[function.session start]:无法发送会话缓存限制器-在/Users/Eamon/Sites/templates/showuser.php:1第2行的/Users/Eamon/Sites/templates/showuser.php中已经发送了头(输出开始于/Users/Eamon/Sites/templates/showuser.php:1),我将用showuser.php上的内容更新我的答案(个人资料页(.@SharonHaimPourthanks…从上面的答案中得到了它-但是如果你阅读我上面的评论,我会得到一个新的错误。
include 'session.php';
<?php
include "path_to_session.php";
$handler = new Session();