Dateien:
common/Common.config.php
include/session.inc.php
session_test.php
get_session_test.php
get_session_test2.php
Common.config.php
/*
* Common config
* Von 恋太后天
*/
/*
* Database config
*/
define( "DBTYPE", "mysql" );
$database = array
(
"mysql" => array
"password" => ; "",
"dbname" => ""
),
(
"localhost",
"user" => "session",
"password" => "session",
"dbname"
)
);
?>
session.inc.php
//使用mysql存放session 函数表
// von 恋太后天 28.04.2005
if (!isset($include_path)) $include_path = '';
{
include ($include_path."common/Common.config.php");
}
$DBsess_link = mysql_connect( $DBsess["host"], $DBsess["user"], $DBsess["password"])
oder sterben ("Fehler:Kann keine Verbindung zum MySQL-Server herstellen." );
$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");
function sess_open($path, $name)
return true;
}
{
return true;}
function sess_read($id)
{
mysql_select_db($DBsess["dbname"]);
$now = time();
$result = mysql_query("SELECT `data` FROM `sessions`
WHERE. `id`= '$ id' UND `expiry_time` > $now", $DBsess_link);
{
return $data;
}
return false;
}
function sess_write($id, $data)
{
global $DBsess , $DBsess_link, $SESS_LIFE;
mysql_select_db($DBsess["dbname"]);
$expiry_time = time() + $SESS_LIFE;
{
$data = addslashes($data);
}
if ( !$result )
{
$result = mysql_query("UPDATE `sessions` SET `data`='$data', `expiry_time`=$expiry_time
function sess_destroy($id)
{
global $DBsess , $DBsess_link;
mysql_select_db($DBsess["dbname"]);
$query = mysql_query("DELETE FROM `session ` WHERE `id`='$id'");
return $query;
}
function sess_gc($maxlifetime)
{
global $DBsess , $DBsess_link;
$query = mysql_query("DELETE FROM `sessions` WHERE `expiry_time` < " . time(), $DBsess_link);
return mysql_affected_rows($DBsess_link);
}
session_module_name();
session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");
?>
session_test.php
// Test für die Verwendung von Sitzung
include ("common/Common.config.php ");
include ("include/session.inc.php");
session_start();
$_SESSION["abc"] = "A: Ich komme wieder !";
$_SESSION["meto"] = "B: Ich auch ";
echo "
?>
get_session_test.php
// Test für die Verwendung von Sitzung
include ("common/Common.config. php");
include ("include/session.inc.php");
session_start();
/*
* www.knowsky.com
*/
$_SESSION["c"] = "
C: Ich werde U folgen. ^0^!";
print($_SESSION["abc"]);
print("< br>");
print($_SESSION["meto"]);
echo "
".
"
?>
get_session_test2.php
//get_session_test2.php
// Test für die Verwendung von session
include ("common/Common.config.php");
include ("include/session.inc.php");
session_start();
print ($_SESSION["c"]);
?>