내 앱이 세션 처리기를 찾을 수없는 이유는 무엇입니까? 나는 오류이 얻을 :치명적인 오류 : 'xxx'클래스가 없습니다.
Fatal error: Class 'Session' not found in /Users/Eamon/Sites/index.php on line 2
편집 2 (리팩토링의 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();
?>
session.php 여기에서 복사 : http://phpmaster.com/writing-custom-session-handlers/) :
편집 (아래 주석에서 제안한대로 인터페이스 추가).
<?php
interface SessionHandlerInterface
{
public function open($path, $name);
public function read($sessionId);
public function write($sessionId, $data);
public function close();
public function destroy($sessionId);
public function gc($lifetime);
}
class Session implements SessionHandlerInterface {
// implement interfaces here
function open($path, $name) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "INSERT INTO session SET session_id =" . $db->quote($sessionId) . ", session_data = '' ON DUPLICATE KEY UPDATE session_lastaccesstime = NOW()";
$db->query($sql);
}
function read($sessionId) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "SELECT session_data FROM session where session_id =" . $db->quote($sessionId);
$result = $db->query($sql);
$data = $result->fetchColumn();
$result->closeCursor();
return $data;
}
function write($sessionId, $data) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "INSERT INTO session SET session_id =" . $db->quote($sessionId) . ", session_data =" . $db->quote($data) . " ON DUPLICATE KEY UPDATE session_data =" . $db->quote($data);
$db->query($sql)
}
function close() {
$sessionId = session_id();
//perform some action here
}
function destroy($sessionId) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "DELETE FROM session WHERE session_id =" . $db->quote($sessionId);
$db->query($sql);
setcookie(session_name(), "", time() - 3600);
}
function gc($lifetime) {
$db = new PDO("mysql:host=localhost;dbname=itit", "root", "bonjour3");
$sql = "DELETE FROM session WHERE session_lastaccesstime < DATE_SUB(NOW(), INTERVAL " . $lifetime . " SECOND)";
$db->query($sql);
}
}
?>
어떤 도움을 주셔서 감사합니다!
Warning: Wrong parameter count for session_set_save_handler() in /Users/Eamon/Sites/index.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Users/Eamon/Sites/index.php:1) in /Users/Eamon/Sites/index.php on line 5
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Users/Eamon/Sites/index.php:1) in /Users/Eamon/Sites/index.php on line 5
UPDATE :
UPDATE
나는 그러나 나는 밖으로 정렬 필요는 몇 가지 새로운 오류가, 내 변경 사항을 반영하기 위해 내 위의 코드를 편집 ... 몇 가지 오류를 수정 분명히 2
,
The function session_set_save_handler requires six parameters be passed to it.
나는이 여기에 읽기 : http://forums.phpfreaks.com/topic/18940-session-set-save-handler-problem/
UPDATE 3
위의 매개 변수 오류를 수정했습니다 ... 그냥 내 index.php를 직접 세션 클래스를 넣어 (내 변경 사항을 반영하기 위해 위의 내 코드를 변경 index.php에서). 기본적으로 ... 정확히 여기 예제 2에서 볼 수있는 것이 있습니다 - http://php.net/manual/en/function.session-set-save-handler.php.
다음Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Users/Eamon/Sites/templates/showuser.php:1) in /Users/Eamon/Sites/templates/showuser.php on line 2
가 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);
?>
다시 ... (I가되는 index.php의 변경 사항을 확인 session.php 파일이 더 이상 존재하지 않음).
@ YogeshSuthar..fixed -하지만 지금은'치명적인 오류 : Interface 'SessionHandlerInterface'가 xxx'에 없습니다. 이걸 찾았습니다 - http://php.net/manual/en/class.sessionhandlerinterface.php. 네임 스페이스에 추가하는 것을 말하는 아래에 주석이 있습니다 ... 그게 무슨 뜻인지는 몰라요. – ewizard
@ewizard 해당 인터페이스의 경로도 포함해야합니다. –
그래서 "SessionHandlerInterface.php"라는 파일에 인터페이스를 생성해야합니까? 또는 어딘가에서 그것을 불러올 수 있습니까? 나는이 파일을 내 디렉토리에 가지고 있지 않습니다. – ewizard