当前位置: 首页>>代码示例>>PHP>>正文


PHP session_set_save_handler函数代码示例

本文整理汇总了PHP中session_set_save_handler函数的典型用法代码示例。如果您正苦于以下问题:PHP session_set_save_handler函数的具体用法?PHP session_set_save_handler怎么用?PHP session_set_save_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了session_set_save_handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xoonips_session_regenerate

function xoonips_session_regenerate()
{
    $old_sessid = session_id();
    session_regenerate_id();
    $new_sessid = session_id();
    session_id($old_sessid);
    session_destroy();
    $old_session = $_SESSION;
    session_id($new_sessid);
    $sess_handler =& xoops_gethandler('session');
    session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc'));
    session_start();
    $_SESSION = array();
    foreach (array_keys($old_session) as $key) {
        $_SESSION[$key] = $old_session[$key];
    }
    // write and close session for xnp_is_valid_session_id()
    session_write_close();
    // restart session
    session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc'));
    session_start();
    $_SESSION = array();
    foreach (array_keys($old_session) as $key) {
        $_SESSION[$key] = $old_session[$key];
    }
}
开发者ID:XoopsModules25x,项目名称:xcl-module-xoonips,代码行数:26,代码来源:session.php

示例2: start

 public static function start($lifetime = 0, $path = '/', $domain = NULL)
 {
     if (!self::$_initialized) {
         if (!is_object(Symphony::Database()) || !Symphony::Database()->connected()) {
             return false;
         }
         $cache = Cache::instance()->read('_session_config');
         if (is_null($cache) || $cache === false) {
             self::create();
             Cache::instance()->write('_session_config', true);
         }
         if (!session_id()) {
             ini_set('session.save_handler', 'user');
             ini_set('session.gc_maxlifetime', $lifetime);
             ini_set('session.gc_probability', '1');
             ini_set('session.gc_divisor', '3');
         }
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false);
         if (strlen(session_id()) == 0) {
             if (headers_sent()) {
                 throw new Exception('Headers already sent. Cannot start session.');
             }
             session_start();
         }
         self::$_initialized = true;
     }
     return session_id();
 }
开发者ID:brendo,项目名称:symphony-3,代码行数:29,代码来源:class.session.php

示例3: osTicketSession

 function osTicketSession($ttl = 0)
 {
     $this->ttl = $ttl ?: ini_get('session.gc_maxlifetime') ?: SESSION_TTL;
     // Set osTicket specific session name.
     session_name('OSTSESSID');
     // Forced cleanup on shutdown
     register_shutdown_function('session_write_close');
     // Set session cleanup time to match TTL
     ini_set('session.gc_maxlifetime', $ttl);
     if (OsticketConfig::getDBVersion()) {
         return session_start();
     }
     # Cookies
     // Avoid setting a cookie domain without a dot, thanks
     // http://stackoverflow.com/a/1188145
     $domain = null;
     if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], '.') !== false && !Validator::is_ip($_SERVER['HTTP_HOST'])) {
         // Remote port specification, as it will make an invalid domain
         list($domain) = explode(':', $_SERVER['HTTP_HOST']);
     }
     session_set_cookie_params($ttl, ROOT_PATH, $domain, osTicket::is_https());
     //Set handlers.
     session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc'));
     //Start the session.
     session_start();
 }
开发者ID:dmiguel92,项目名称:osTicket-1.8,代码行数:26,代码来源:class.ostsession.php

示例4: start

 public static function start($lifetime = 0, $path = '/', $domain = NULL)
 {
     if (!self::$_initialized) {
         if (!is_object(Symphony::Database()) || !Symphony::Database()->isConnected()) {
             return false;
         }
         self::$_cache = new Cacheable(Symphony::Database());
         $installed = self::$_cache->check('_session_config');
         if (!$installed) {
             if (!self::createTable()) {
                 return false;
             }
             self::$_cache->write('_session_config', true);
         }
         ini_set('session.save_handler', 'user');
         ini_set('session.gc_maxlifetime', $lifetime);
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false);
         if (strlen(session_id()) == 0) {
             if (headers_sent()) {
                 throw new Exception('Headers already sent. Cannot start session.');
             }
             session_start();
         }
         self::$_initialized = true;
     }
     return session_id();
 }
开发者ID:knupska,项目名称:symphony-2,代码行数:28,代码来源:class.session.php

示例5: __construct

 /**
  * 构造函数
  * 
  */
 public function __construct()
 {
     $this->db = pc_base::load_model('session_model');
     $this->lifetime = pc_base::load_config('system', 'session_ttl');
     session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc'));
     session_start();
 }
开发者ID:klj123wan,项目名称:czsz,代码行数:11,代码来源:session_mysql.class.php

示例6: Init

 public static function Init()
 {
     if (CSecuritySessionVirtual::isStorageEnabled()) {
         if (!CSecuritySessionVirtual::init()) {
             self::triggerFatalError("Failed to initialize Virtual session handler");
         }
         //may return false with session.auto_start is set to On
         if (session_set_save_handler(array("CSecuritySessionVirtual", "open"), array("CSecuritySessionVirtual", "close"), array("CSecuritySessionVirtual", "read"), array("CSecuritySessionVirtual", "write"), array("CSecuritySessionVirtual", "destroy"), array("CSecuritySessionVirtual", "gc"))) {
             register_shutdown_function("session_write_close");
         }
     } elseif (CSecuritySessionMC::isStorageEnabled()) {
         if (!CSecuritySessionMC::Init()) {
             self::triggerFatalError("Failed to initialize Memcache session handler");
         }
         //may return false with session.auto_start is set to On
         if (session_set_save_handler(array("CSecuritySessionMC", "open"), array("CSecuritySessionMC", "close"), array("CSecuritySessionMC", "read"), array("CSecuritySessionMC", "write"), array("CSecuritySessionMC", "destroy"), array("CSecuritySessionMC", "gc"))) {
             register_shutdown_function("session_write_close");
         }
     } else {
         if (!CSecuritySessionDB::Init()) {
             self::triggerFatalError("Failed to initialize DB session handler");
         }
         //may return false with session.auto_start is set to On
         if (session_set_save_handler(array("CSecuritySessionDB", "open"), array("CSecuritySessionDB", "close"), array("CSecuritySessionDB", "read"), array("CSecuritySessionDB", "write"), array("CSecuritySessionDB", "destroy"), array("CSecuritySessionDB", "gc"))) {
             register_shutdown_function("session_write_close");
         }
     }
 }
开发者ID:rasuldev,项目名称:torino,代码行数:28,代码来源:session.php

示例7: __construct

 public function __construct($conn, $tabela)
 {
     self::$_conn = $conn;
     self::$_table = $tabela;
     session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc'));
     register_shutdown_function('session_write_close');
 }
开发者ID:marcelocaixeta,项目名称:zf1,代码行数:7,代码来源:Db.php

示例8: __construct

 /**
  * Default constructor
  */
 public function __construct($db, $config)
 {
     $this->db = $db;
     $this->start = microtime(true);
     $this->ip = rcube_utils::remote_addr();
     $this->logging = $config->get('log_session', false);
     $lifetime = $config->get('session_lifetime', 1) * 60;
     $this->set_lifetime($lifetime);
     // use memcache backend
     $this->storage = $config->get('session_storage', 'db');
     if ($this->storage == 'memcache') {
         $this->memcache = rcube::get_instance()->get_memcache();
         // set custom functions for PHP session management if memcache is available
         if ($this->memcache) {
             ini_set('session.serialize_handler', 'php');
             session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'mc_read'), array($this, 'mc_write'), array($this, 'mc_destroy'), array($this, 'gc'));
         } else {
             rcube::raise_error(array('code' => 604, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Failed to connect to memcached. Please check configuration"), true, true);
         }
     } else {
         if ($this->storage != 'php') {
             ini_set('session.serialize_handler', 'php');
             // set custom functions for PHP session management
             session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'db_read'), array($this, 'db_write'), array($this, 'db_destroy'), array($this, 'gc'));
             $this->table_name = $this->db->table_name('session', true);
         }
     }
 }
开发者ID:yozhi,项目名称:YetiForceCRM,代码行数:31,代码来源:rcube_session.php

示例9: __construct

 /**
  * Constructor
  */
 public function __construct()
 {
     session_set_save_handler(array($this, "open"), array($this, "close"), array($this, "read"), array($this, "write"), array($this, "destroy"), array($this, "gc"));
     if (!extension_loaded('mcrypt')) {
         throw new Exception("The SecureSession class needs the Mcrypt PHP extension, please install it.");
     }
 }
开发者ID:husnixs,项目名称:PHP-Secure-Session,代码行数:10,代码来源:SecureSession.php

示例10: start

 /**
  * Starts a Session object, only if one doesn't already exist. This function maps
  * the Session Handler functions to this classes methods by reading the default
  * information from the PHP ini file.
  *
  * @link http://php.net/manual/en/function.session-set-save-handler.php
  * @link http://php.net/manual/en/function.session-set-cookie-params.php
  * @param integer $lifetime
  *  How long a Session is valid for, by default this is 0, which means it
  *  never expires
  * @param string $path
  *  The path the cookie is valid for on the domain
  * @param string $domain
  *  The domain this cookie is valid for
  * @param boolean $httpOnly
  *  Whether this cookie can be read by Javascript. By default the cookie
  *  cannot be read by Javascript
  * @param boolean $secure
  *  Whether this cookie should only be sent on secure servers. By default this is
  *  false, which means the cookie can be sent over HTTP and HTTPS
  * @throws Exception
  * @return string|boolean
  *  Returns the Session ID on success, or false on error.
  */
 public static function start($lifetime = 0, $path = '/', $domain = null, $httpOnly = true, $secure = false)
 {
     if (!self::$_initialized) {
         if (!is_object(Symphony::Database()) || !Symphony::Database()->isConnected()) {
             return false;
         }
         if (session_id() == '') {
             ini_set('session.save_handler', 'user');
             ini_set('session.gc_maxlifetime', $lifetime);
             ini_set('session.gc_probability', '1');
             ini_set('session.gc_divisor', Symphony::Configuration()->get('session_gc_divisor', 'symphony'));
         }
         session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc'));
         session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), $secure, $httpOnly);
         session_cache_limiter('');
         if (session_id() == '') {
             if (headers_sent()) {
                 throw new Exception('Headers already sent. Cannot start session.');
             }
             register_shutdown_function('session_write_close');
             session_start();
         }
         self::$_initialized = true;
     }
     return session_id();
 }
开发者ID:rc1,项目名称:WebAppsWithCmsStartHere,代码行数:50,代码来源:class.session.php

示例11: init

 public static function init()
 {
     session::$db = db::get(true);
     if (!ini_get('session.gc_probability')) {
         @ini_set('session.gc_probability', 1);
     }
     if (!ini_get('session.gc_divisor')) {
         @ini_set('session.gc_divisor', 100);
     }
     session_set_save_handler(array('session', 'open'), array('session', 'close'), array('session', 'read'), array('session', 'write'), array('session', 'destroy'), array('session', 'gc'));
     $hash = null;
     session_name('sess_hash');
     if (!html_get_cookie('sess_hash')) {
         if ($hash = session::restore()) {
             session_id($hash);
         } else {
             html_set_cookie('user_logon', '', time() - YEAR_IN_SECONDS);
             html_set_cookie('user_token', '', time() - YEAR_IN_SECONDS);
         }
     }
     session_start();
     if (!isset($_SESSION['UID'])) {
         $_SESSION['UID'] = 0;
     }
     if (!is_null($hash)) {
         session::refresh_csrf_token();
     }
 }
开发者ID:DeannaG65,项目名称:BeehiveForum,代码行数:28,代码来源:session.inc.php

示例12: __construct

 public function __construct()
 {
     // 这里使用静态的调用方法不行了。必须传入一个对象
     ini_set('session.save_handler', 'user');
     session_set_save_handler(array($this, 'sess_open'), array($this, 'sess_close'), array($this, 'sess_read'), array($this, 'sess_write'), array($this, 'sess_destroy'), array($this, 'sess_gc'));
     @session_start();
 }
开发者ID:dab1993,项目名称:myeshop,代码行数:7,代码来源:SessionDBTool.class.php

示例13: __construct

 public function __construct(array $options = array())
 {
     $this->setMetadataBag();
     // create IP finger print
     $current_ipaddr = '';
     $_REMOTE_ADDR = System::serverGetVar('REMOTE_ADDR');
     $_HTTP_X_FORWARDED_FOR = System::serverGetVar('HTTP_X_FORWARDED_FOR');
     if (System::getVar('sessionipcheck')) {
         // feature for future release
     }
     // create the ip fingerprint
     $current_ipaddr = md5($_REMOTE_ADDR . $_HTTP_X_FORWARDED_FOR);
     $this->object = array('lastused' => date('Y-m-d H:i:s', time()), 'uid' => 0, 'ipaddr' => $current_ipaddr, 'remember' => 0, 'vars' => '');
     $path = System::getBaseUri();
     if (empty($path)) {
         $path = '/';
     } elseif (substr($path, -1, 1) != '/') {
         $path .= '/';
     }
     $options = array_merge(array('auto_start' => 0, 'use_cookies' => 1, 'gc_probability' => System::getVar('gc_probability'), 'gc_divisor' => 10000, 'gc_maxlifetime' => System::getVar('secinactivemins') * 60, 'hash_function' => 1, 'cookie_path' => $path), $options);
     $this->setOptions($options);
     session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc'));
     register_shutdown_function('session_write_close');
     $this->saveHandler = new SessionHandlerProxy($this);
 }
开发者ID:planetenkiller,项目名称:core,代码行数:25,代码来源:LegacySessionStorage.php

示例14: __construct

 public function __construct($config)
 {
     $this->sessionDbName = $config['storageName'];
     $this->sessionDbConn = new Resources\Database($config['driverConnection']);
     session_set_save_handler(array($this, 'sessionStart'), array($this, 'sessionEnd'), array($this, 'sessionRead'), array($this, 'sessionWrite'), array($this, 'sessionDestroy'), array($this, 'sessionGc'));
     parent::__construct($config);
 }
开发者ID:finzaiko,项目名称:Panada,代码行数:7,代码来源:Database.php

示例15: register

 /**
  * Register session connection driver
  *
  * Registers the session connection driver as current session handler
  *
  * See {@link http://php.net/session_set_save_handler
  * session_set_save_handler()} for more details
  *
  * @return bool
  */
 public function register()
 {
     if ($this->_registered !== true) {
         $this->_registered = @session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'clean'));
     }
     return $this->_registered;
 }
开发者ID:jvirtism,项目名称:AnEngine,代码行数:17,代码来源:driver.class.php


注:本文中的session_set_save_handler函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。