PHP session_set_save_handler不保存到数据库



我创建了一个类来将会话数据保存到数据库中。 它不会保存到数据库中,并且没有错误。知道为什么吗?这是类。

 <?php
class Session {

public function __construct(){
    //set handle to override SESSION
    $session_id = session_id();
    $session_name = session_name();
    $session_path = session_save_path();
    echo "in class";
}
function open(){
    include("includes/globals.php");
    global $_sess_db;
echo "in open";
    if(mysql_connect('127.0.0.1','root','') or die(mysql_error())){
        return mysql_select_db($CallPro_dbname, $_sess_db);
        echo "connected";
    }
    return FALSE;
}
function close(){
    global $_sess_db;
    return mysql_close($_sess_db);
}
function read($session_id){
    mysql_connect('127.0.0.1','root','');
            $record;
    $sql = "select * from callprodev.session_data where agentid = '".$_SESSION['agentid']."'";
    $result = mysql_query($sql,$_sess_db)or die(mysql_error());
    $record = mysql_fetch_assoc($result)or die(mysql_error());
    echo "read";
}
function write($session_id){
    mysql_connect('127.0.0.1','root','');
            $access = time();
    $access = mysql_real_escape_string($access);
    $sql = "REPLACE
    INTO    callprodev.session_data
    VALUES  (
    '{$_SESSION['agentid']}',
    '{$_SESSION['extension']}',
    '{$_SESSION['page']}',
    '{$_SESSION['vduser']}',
    '{$_SESSION['vdpass']}',
    '{$_SESSION['action_main_plugin']}',
    '{$_SESSION['caller_phone']}',
    '{$_SESSION['campaignid']}',
    '{$_SESSION['uniqueid']}',
    '{$_SESSION['dialed']}',
    '{$_SESSION['rurl']}',
    '{$_SESSION['reference_id']}',
    '{$_SESSION['contactid']}',
    '{$_SESSION['groupid']}',
    '{$_SESSION['script_info_plugin']}',
    '{$_SESSION['flags']}',
    '{$_SESSION['dispositioned']}'
    )";
    echo "write";
    return mysql_query($sql, $_sess_db)or die(mysql_error());
}
function destroy($session_id){
    mysql_connect('127.0.0.1','root','');
            $sql = "delete from callprodev.session_data where id = '{$_SESSION['agentid']}'";
            echo "destroy";
    return mysql_query($sql, $_sess_db)or die(mysql_error());
}
function gc($max){
}
}
$session_record = new Session();
session_set_save_handler(
    array($session_record, "open"),
    array($session_record, "close"),
    array($session_record, "read"),
    array($session_record, "write"),
    array($session_record, "destroy"),
    array($session_record, "gc"));
register_shutdown_function('session_write_close');

session_start();

会话包含在 init.php 文件中。它是这样称呼的。

include("classes/Session.php");

$session_record                     = new Session();
session_set_save_handler(
    array($session_record, "open"),
    array($session_record, "close"),
    array($session_record, "read"),
    array($session_record, "write"),
    array($session_record, "destroy"),
    array($session_record, "gc"));
session_start();

试试

session_set_save_handler(
    array(&$session_record, "open"),
    array(&$session_record, "close"),
    array(&$session_record, "read"),
    array(&$session_record, "write"),
    array(&$session_record, "destroy"),
    array(&$session_record, "gc"));

相关内容

  • 没有找到相关文章

最新更新