Habari\Session::write PHP Метод

write() публичный статический Метод

Commit $_SESSION data to the database for this user.
public static write ( )
    public static function write()
    {
        if (!isset(self::$session_id)) {
            self::create();
        }
        $remote_address = Utils::get_ip();
        // not always set, even by real browsers
        $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
        $dowrite = self::changed();
        if (isset($_SESSION)) {
            // get the data from the ArrayObject
            $data = $_SESSION;
        } else {
            $dowrite = false;
            $data = array();
        }
        // but let a plugin make the final decision. we may want to ignore search spiders, for instance
        $dowrite = Plugins::filter('session_write', $dowrite, self::$session_id, $data);
        if ($dowrite) {
            // DB::update() checks if the record key exists, and inserts if not
            $record = array('ip' => self::get_subnet($remote_address), 'expires' => DateTime::create()->int + self::$lifetime, 'ua' => MultiByte::substr($user_agent, 0, 255), 'data' => serialize($data));
            DB::update(DB::table('sessions'), $record, array('token' => self::$session_id));
        }
    }