验证中...
Languages: PHP
Categories: 其他
Latest update 2019-01-19 08:01
gistfile1.txt
Raw Copy
<?php
//Define open_session function
$sdbc = NULL;
function open_session()
{
global $sdbc;
//create a database connection
$sdbc = mysqli_connect('127.0.0.1','root','houzi123','mytest');
return true;
}
function close_session()
{
global $sdbc;
return mysqli_close();
}
function read_session($sid)
{
global $sdbc;
$q = sprintf('select data from sessions where id="%s"',mysqli_real_escape_string($sdbc,$sid));
$r = mysqli_query($sdbc, $q);
if(mysqli_num_rows($r) == 1)
{
list($data) = mysqli_fetch_array($r, MYSQLI_NUM);
return $data;
}else
{
return '';
}
}
function write_session($sid, $data)
{
global $sdbc;
$q = sprintf('replace into sessions (id, data) values ("%s","%s")', mysqli_real_escape_string($sdbc,$sid),mysqli_real_escape_string($sdbc,$data));
$r = mysqli_query($sdbc, $q);
return true;
}
function destory_session($sid)
{
global $sdbc;
$q = sprintf('delete from sessions where id="%s"',mysqli_real_escape_string($sdbc,$sid));
$r = mysqli_query($sdbc, $q);
//clear session
$_SESSION = [];
return true;
}
function clean_session($expire)
{
global $sdbc;
$q = sprintf('delete from sessions where date_add(last_accessed, intval %d second) < now()',(int) $expire);
$r = mysqli_query($sdbc, $q);
return true;
}
session_set_save_handler('open_session','close_session','read_session','write_session','destory_session','clean_session');
session_start();
var_dump($_SESSION);
$_SESSION['nidoxz'] = '132312';
$_SESSION['why'] = 'qqdsccxz';
var_dump($_SESSION);
session_destroy();
session_write_close();

Comment list( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025