本文整理匯總了PHP中cookie::lifetime方法的典型用法代碼示例。如果您正苦於以下問題:PHP cookie::lifetime方法的具體用法?PHP cookie::lifetime怎麽用?PHP cookie::lifetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cookie
的用法示例。
在下文中一共展示了cookie::lifetime方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: start
/**
* Starts a new session
*
* <code>
*
* s::start();
* // do whatever you want with the session now
*
* </code>
*
*/
public static function start()
{
if (session_status() === PHP_SESSION_ACTIVE) {
return true;
}
// store the session name
static::$cookie += array('lifetime' => 0, 'path' => ini_get('session.cookie_path'), 'domain' => ini_get('session.cookie_domain'), 'secure' => r::secure(), 'httponly' => true);
// set the custom session name
session_name(static::$name);
// make sure to use cookies only
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
// try to start the session
if (!session_start()) {
return false;
}
if (!setcookie(static::$name, session_id(), cookie::lifetime(static::$cookie['lifetime']), static::$cookie['path'], static::$cookie['domain'], static::$cookie['secure'], static::$cookie['httponly'])) {
return false;
}
// mark it as started
static::$started = true;
// check if the session is still valid
if (!static::check()) {
return static::destroy();
}
return true;
}