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


PHP session_set_cookie_params函数代码示例

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


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

示例1: sec_session_start

function sec_session_start()
{
    $session_name = 'exatest_session_id';
    //Asignamos un nombre de sesión
    $secure = false;
    //mejor en config.php Lo ideal sería true para trabajar con https
    $httponly = true;
    // Obliga a la sesión a utilizar solo cookies.
    // Habilitar este ajuste previene ataques que impican pasar el id de sesión en la URL.
    if (ini_set('session.use_only_cookies', 1) === FALSE) {
        $action = "error";
        $error = "No puedo iniciar una sesion segura (ini_set)";
    }
    // Obtener los parámetros de la cookie de sesión
    $cookieParams = session_get_cookie_params();
    session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
    //Marca la cookie como accesible sólo a través del protocolo HTTP.
    //Esto siginifica que la cookie no será accesible por lenguajes de script,
    // tales como JavaScript.
    //Este ajuste puede ayudar de manera efectiva a reducir robos de
    //indentidad a través de ataques
    // Incia la sesión PHP
    session_name($session_name);
    session_start();
    // Actualiza el id de sesión actual con uno generado más reciente
    //Ayuda a evitar ataques de fijación de sesión
    session_regenerate_id(true);
}
开发者ID:andoniaf,项目名称:GBD_exatest,代码行数:28,代码来源:functions.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: init

 /**
  * Initialize session
  */
 public static function init()
 {
     // Force cookie path (but do not change lifetime)
     $cookie = session_get_cookie_params();
     // Default cookie expiration and path.
     $cookiedir = '';
     if (dirname($_SERVER['SCRIPT_NAME']) != '/') {
         $cookiedir = dirname($_SERVER["SCRIPT_NAME"]) . '/';
     }
     $ssl = false;
     if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
         $ssl = true;
     }
     session_set_cookie_params($cookie['lifetime'], $cookiedir, $cookie['domain'], $ssl);
     // Use cookies to store session.
     ini_set('session.use_cookies', 1);
     // Force cookies for session  (phpsessionID forbidden in URL)
     ini_set('session.use_only_cookies', 1);
     if (!session_id()) {
         // Prevent php to use sessionID in URL if cookies are disabled.
         ini_set('session.use_trans_sid', false);
         if (!empty(self::$sessionName)) {
             session_name(self::$sessionName);
         }
         session_start();
     }
 }
开发者ID:Scorry,项目名称:readityourself,代码行数:30,代码来源:Session.php

示例5: start

 static function start()
 {
     include_once __DIR__ . '/sessionDrivers/' . Settings::$sessionDriver . '.php';
     //self::$driver = new Settings::$sessionDriver();
     //session_set_save_handler(array(self::$driver, 'open'),array(self::$driver, 'close'),array(self::$driver, 'read'),
     //            array(self::$driver, 'write'),array(self::$driver, 'destroy'),array(self::$driver, 'gc'));
     register_shutdown_function('session_write_close');
     if (in_array(Settings::$session_hash, hash_algos())) {
         ini_set('session.hash_function', Settings::$session_hash);
     }
     ini_set('session.hash_bits_per_character', Settings::$hash_bits_per_character);
     $cookieParams = session_get_cookie_params();
     session_set_cookie_params(Settings::$sessionLifetime, $cookieParams["path"], $cookieParams["domain"], Settings::$secure, Settings::$httpOnly);
     session_name(Settings::$NAME);
     //буферизуем заголовок
     ob_start();
     //включаем CORS, если указано в настройках /*
     if (isset(Settings::$CORS) && Settings::$CORS && !empty($_SERVER['HTTP_ORIGIN'])) {
         header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
         header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
         header('Access-Control-Max-Age: 1000');
         header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
     }
     //включаем сессию
     session_start();
     ob_end_flush();
     //посылаем заголовок
 }
开发者ID:pdanver,项目名称:mir-ndv,代码行数:28,代码来源:Session.php

示例6: init

 public function init()
 {
     session_set_cookie_params($this->expire, $this->path, $this->domain, $this->secure, $this->httpOnly);
     if ($this->autoStart) {
         $this->open();
     }
 }
开发者ID:nbaiwan,项目名称:yav,代码行数:7,代码来源:CSession.php

示例7: __construct

 /**
  * Default constructor.
  *
  * @access  public
  * @param   array   $config
  */
 public function __construct($config = array())
 {
     // initialize the database
     $this->_init(empty($config) ? $this->_config : $config);
     // set object as the save handler
     session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc'));
     // set some important session vars
     ini_set('session.auto_start', 0);
     ini_set('session.gc_probability', 1);
     ini_set('session.gc_divisor', 100);
     ini_set('session.gc_maxlifetime', $this->_config['lifetime']);
     ini_set('session.referer_check', '');
     ini_set('session.entropy_file', '/dev/urandom');
     ini_set('session.entropy_length', 16);
     ini_set('session.use_cookies', 1);
     ini_set('session.use_only_cookies', 1);
     ini_set('session.use_trans_sid', 0);
     ini_set('session.hash_function', 1);
     ini_set('session.hash_bits_per_character', 5);
     // disable client/proxy caching
     session_cache_limiter('nocache');
     // set the cookie parameters
     session_set_cookie_params($this->_config['lifetime'], $this->_config['cookie_path'], $this->_config['cookie_domain']);
     // name the session
     session_name('mongo_sess');
     // start it up
     session_start();
 }
开发者ID:halfdan,项目名称:MongoSession,代码行数:34,代码来源:MongoSession.php

示例8: startInit

 /** startInit() initiates the environment
  * @return void
  */
 public static function startInit()
 {
     @set_time_limit(0);
     @error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
     @ini_set('session.save_handler', 'mm');
     @ini_set('session.cookie_httponly', true);
     @ob_start('sanitize_output');
     @session_start();
     @session_cache_limiter('no-cache');
     @session_set_cookie_params(0, null, null, true, true);
     @set_magic_quotes_runtime(0);
     self::verCheck();
     self::extCheck();
     foreach ($_REQUEST as $key => $val) {
         $_REQUEST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
     }
     foreach ($_GET as $key => $val) {
         $_GET[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
     }
     foreach ($_POST as $key => $val) {
         $_POST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
     }
     foreach (array('node', 'sub', 'printertype', 'id', 'sub', 'crit', 'sort', 'confirm', 'tab') as $x) {
         global ${$x};
         ${$x} = isset($_REQUEST[$x]) ? filter_var($_REQUEST[$x], FILTER_SANITIZE_STRING) : '';
     }
     unset($x);
     new System();
     new Config();
 }
开发者ID:bramverstraten,项目名称:fogproject,代码行数:33,代码来源:init.php

示例9: __construct

 protected function __construct()
 {
     /* Call the parent constructor in case it should become
      * necessary in the future.
      */
     parent::__construct();
     /* Initialize the php session handling.
      *
      * If session_id() returns a blank string, then we need
      * to call session start. Otherwise the session is already
      * started, and we should avoid calling session_start().
      */
     if (session_id() === '') {
         $config = SimpleSAML_Configuration::getInstance();
         $params = $this->getCookieParams();
         $version = explode('.', PHP_VERSION);
         if ((int) $version[0] === 5 && (int) $version[1] < 2) {
             session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure']);
         } else {
             session_set_cookie_params($params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
         }
         $this->cookie_name = $config->getString('session.phpsession.cookiename', NULL);
         if (!empty($this->cookie_name)) {
             session_name($this->cookie_name);
         } else {
             $this->cookie_name = session_name();
         }
         $savepath = $config->getString('session.phpsession.savepath', NULL);
         if (!empty($savepath)) {
             session_save_path($savepath);
         }
     }
 }
开发者ID:williamamed,项目名称:Raptor2,代码行数:33,代码来源:SessionHandlerPHP.php

示例10: sessionStart

 static function sessionStart($name, $limit = 0, $path = '/', $domain = null, $secure = null)
 {
     // Set the cookie name before we start.
     session_name($name . '_Session');
     // Set the domain to default to the current domain.
     $domain = isset($domain) ? $domain : isset($_SERVER['SERVER_NAME']);
     // Set the default secure value to whether the site is being accessed with SSL
     $https = isset($secure) ? $secure : isset($_SERVER['HTTPS']);
     // Set the cookie settings and start the session
     session_set_cookie_params($limit, $path, $domain, $secure, true);
     session_start();
     // Make sure the session hasn't expired, and destroy it if it has
     if (self::validateSession()) {
         // Check to see if the session is new or a hijacking attempt
         if (!self::preventHijacking()) {
             // Reset session data and regenerate id
             $_SESSION = array();
             $_SESSION['IPaddress'] = $_SERVER['REMOTE_ADDR'];
             $_SESSION['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
             self::regenerateSession();
             // Give a 5% chance of the session id changing on any request
         } elseif (rand(1, 100) <= 5) {
             self::regenerateSession();
         }
     } else {
         $_SESSION = array();
         session_destroy();
         session_start();
     }
 }
开发者ID:qqalexqq,项目名称:Projects_645,代码行数:30,代码来源:class.SessionManager.php

示例11: 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

示例12: sessionStart

 static function sessionStart($name, $limit = 0, $secure = null)
 {
     # definovani jmena
     session_name($name . '_session');
     # zjisteni sifrovani
     $https = isset($secure) ? $secure : isset($_SERVER['HTTPS']);
     # vlozeni nastaveni do sessionu
     session_set_cookie_params($limit, '/', '.' . $_SERVER['SERVER_NAME'], $secure, true);
     session_start();
     if (self::validateSession()) {
         # kontrola parametru uzivatele a sessionu
         if (!self::preventHijacking()) {
             $_SESSION = array();
             $_SESSION['IPaddress'] = $_SERVER['REMOTE_ADDR'];
             $_SESSION['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
         } elseif (rand(1, 100) <= 5) {
             # nahodne regeneruje sessiony 5% pripadu
             self::regenerateSession();
         }
     } else {
         # pokud session neproleze validaci, je zrusen
         $_SESSION = array();
         session_destroy();
         session_start();
     }
 }
开发者ID:Otas13,项目名称:php-mvc,代码行数:26,代码来源:SessionManager.php

示例13: init_session

 function init_session()
 {
     global $opt;
     if ($this->session_initalized != true) {
         session_name('SESSION');
         session_set_cookie_params($opt['session']['expire']['cookie'], $opt['session']['path'], $opt['session']['domain']);
         session_start();
         if ($opt['session']['check_referer']) {
             if (isset($_SERVER['REFERER'])) {
                 if (strtolower(substr($_SERVER['REFERER'], 0, strlen($opt['page']['absolute_url']))) != strtolower($opt['page']['absolute_url'])) {
                     $this->createNewSession();
                 }
             }
         }
         if ((isset($_GET['SESSION']) || isset($_POST['SESSION'])) && count($_SESSION) > 0) {
             // comapre and set timestamp
             if (isset($_SESSION['lastcall'])) {
                 if (abs(time() - $_SESSION['lastcall']) > $opt['session']['expire']['url']) {
                     $this->createNewSession();
                 }
             }
             $_SESSION['lastcall'] = time();
         }
         $this->session_initalized = true;
     }
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:26,代码来源:cookie.class.php

示例14: __construct

 public function __construct()
 {
     header('Content-type: text/xml; charset=utf-8');
     header('Cache-control: no-cache, must-revalidate');
     $this->db = mysql_connect(BABEL_DB_HOSTNAME . ':' . BABEL_DB_PORT, BABEL_DB_USERNAME, BABEL_DB_PASSWORD);
     mysql_select_db(BABEL_DB_SCHEMATA);
     mysql_query("SET NAMES utf8");
     mysql_query("SET CHARACTER SET utf8");
     mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
     session_set_cookie_params(2592000);
     session_start();
     $this->User = new User('', '', $this->db);
     global $CACHE_LITE_OPTIONS_SHORT;
     $this->cs = new Cache_Lite($CACHE_LITE_OPTIONS_SHORT);
     /* legacy long cache:
     		global $CACHE_LITE_OPTIONS_LONG;
     		$this->cl = new Cache_Lite($CACHE_LITE_OPTIONS_LONG);
     		*/
     global $ZEND_CACHE_OPTIONS_LONG_FRONTEND;
     global $ZEND_CACHE_OPTIONS_LONG_BACKEND;
     global $ZEND_CACHE_OPTIONS_MEMCACHED;
     if (ZEND_CACHE_MEMCACHED_ENABLED == 'yes') {
         $this->cl = Zend_Cache::factory('Core', 'Memcached', $ZEND_CACHE_OPTIONS_LONG_FRONTEND, $ZEND_CACHE_OPTIONS_MEMCACHED);
     } else {
         $this->cl = Zend_Cache::factory('Core', ZEND_CACHE_TYPE_LONG, $ZEND_CACHE_OPTIONS_LONG_FRONTEND, $ZEND_CACHE_OPTIONS_LONG_BACKEND[ZEND_CACHE_TYPE_LONG]);
     }
     $this->Validator = new Validator($this->db, $this->User);
     if (!isset($_SESSION['babel_ua'])) {
         $_SESSION['babel_ua'] = $this->Validator->vxGetUserAgent();
     }
     $this->URL = new URL();
 }
开发者ID:biaodianfu,项目名称:project-babel,代码行数:32,代码来源:AJAXCore.php

示例15: 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


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