Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未设置PHP会话自定义类会话?_Php_Session - Fatal编程技术网

未设置PHP会话自定义类会话?

未设置PHP会话自定义类会话?,php,session,Php,Session,我有一个自定义类,我正在为自己编写更简单的脚本。我生成生命周期会话和正常会话(正常生命周期)。下面是我的脚本部分,用于创建和获取 创建 public static function create($session_name,$value="") { //check if the $_SESSION was started manually without using our functions... if(!isset($_SESSION)) {

我有一个自定义类,我正在为自己编写更简单的脚本。我生成生命周期会话和正常会话(正常生命周期)。下面是我的脚本部分,用于创建和获取

创建

    public static function create($session_name,$value="") {
        //check if the $_SESSION was started manually without using our functions...
        if(!isset($_SESSION)) {
            //init this- it creates session_start session_id 
            self::init(self::$settings["default_name"]);
        }

        //create array for serialization
        $new_session = array();

        //if our session is an array means we want this session to have some unique properties compared to others
        if( is_array($session_name)) {
            //store the session value in the array
            $new_session["value"] = $session_name["value"];
            //total time is null, this indicates if we want a life expectancy of total 10 hours total or total from current time.
            $total = null;
            if(isset($session_name["lifeclock"])) { //lifeclock should be a hh:mm:ss format to be exploded
                $clock = explode(":",$session_name["lifeclock"]); //we've exploded it now assign it
                $hours = $clock[0]; //hours
                $minutes = $clock[1]; //minutes
                $seconds = $clock[2]; //seconds
                $session_add = 0; //variable to be added to total or not technically
                if(isset($session_name["concurrent"])) {
                    $session_add = time(); //if concurrent time is true assign time to the session_add
                }
                $total = ( $session_add ) + ((int)$hours * 60 * 60) + ((int)$minutes * 60) + (int)$seconds; //broken down math to make all seconds
            }
            if(!isset($total)) { //this is why total is null
                $total = self::$settings["lifetime"]; //if null lifetime we'll use the default lifetime
            }
            session_set_cookie_params( $total, //assing all data to the session_set_cookie_params
                                       isset($session_name["path"]) ? $session_name["path"] : self::$settings["path"],
                                       isset($session_name["domain"]) ? $session_name["domain"] : self::$settings["domain"],
                                       isset($session_name["secure"]) ? $session_name["secure"] : self::$settings["secure"], 
                                       isset($session_name["httponly"]) ? $session_name["httponly"] : self::$settings["httponly"]
                                    ); 
            $new_session["life"] = $total; //we'll also add the time and when it was born
            $new_session["born"] = time(); // so the user can use this later in the programming code

            $_SESSION[$session_name["name"]] = serialize($new_session); //serialize the array
        } elseif(is_string($session_name)) {
            $new_session["value"] = $value; //assign value value
            $new_session["born"] = time(); //assign born time
            $_SESSION[$session_name] = serialize($new_session); //serialize the array
        }
        session_write_close(); //close the lock
    }
获取

    public static function get($session_name,$data = false) {
        //test if session has been opened via manual or programatically 
        if(!isset($_SESSION)) {
            self::init(self::$settings["default_name"]);
        }

        //if data argument is true meaning we don't want all the extra information we'll just return value!
        if($data === false) {
            if(isset($_SESSION[$session_name])) {
                $sess = unserialize($_SESSION[$session_name]);
                if(isset($sess["value"])){
                    return $sess["value"];
                } else return false;
            } else return false;
        } elseif($data === true) {
            return unserialize($_SESSION[$session_name]);
        }

    }
现在这是我的测试文件

<?php
    set_include_path(dirname($_SERVER["DOCUMENT_ROOT"]));
    require "admininit__autoload.php";

    Session::configure(array(
        "default_name"=>"boogie",
        "lifetime"=> 3600,
    ));

    Session::create( array(
        "name"=>"my_session",
        "value"=>"boogie all night long",
        "lifeclock"=>"00:05:00"
    ));

    $session_value = Session::get("my_session");

    var_dump($session_value);
    echo "<pre>";
    print_r($_SESSION);
    echo "</pre>";
?>
因此,这告诉我,get函数返回的
$session\u value
为false,这意味着该死的会话由于某种奇怪的原因没有保存。下面是我在谷歌开发者资源面板中看到的内容

所以对我来说,这意味着某个地方正在创建一个会话。我还检查了我的
/tmp
文件夹,没有看到以sess开头的文件,这是会话的常用文件。有没有任何关于我的问题所在的提示,或者干脆说说这里到底出了什么问题

更新

当代码的创建被取消注释时,我得到了以下信息

bool(false)
Array
(
)
但是当我注释掉创建部分时,它返回这个

array(1) { 
     ["my_session"]=> string(88) "a:3:{s:5:"value";s:21:"boogie all night long";s:4:"life";i:300;s:4:"born";i:1431562088;}"
 } 

 string(21) "boogie all night long"
 Array
 (
    [my_session] => a:3:{s:5:"value";s:21:"boogie all night long";s:4:"life";i:300;s:4:"born";i:1431562088;}
 )
bool(false)
Array
(
)