本文整理匯總了PHP中xPDO::startSession方法的典型用法代碼示例。如果您正苦於以下問題:PHP xPDO::startSession方法的具體用法?PHP xPDO::startSession怎麽用?PHP xPDO::startSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xPDO
的用法示例。
在下文中一共展示了xPDO::startSession方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addSessionContext
/**
* Adds a new context to the user session context array.
*
* @access public
* @param string $context The context to add to the user session.
*/
public function addSessionContext($context)
{
if (!$this->xpdo->startSession()) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Attempt to start a session failed", '', __METHOD__, __FILE__, __LINE__);
return;
}
if (!empty($context)) {
$this->getSessionContexts();
session_regenerate_id(true);
$this->getOne('Profile');
if ($this->Profile && $this->Profile instanceof modUserProfile) {
$ua =& $this->Profile;
if ($ua && !isset($this->sessionContexts[$context]) || $this->sessionContexts[$context] != $this->get('id')) {
$ua->set('failedlogincount', 0);
$ua->set('logincount', $ua->logincount + 1);
$ua->set('lastlogin', $ua->thislogin);
$ua->set('thislogin', time());
$ua->set('sessionid', session_id());
$ua->save();
}
}
$this->sessionContexts[$context] = $this->get('id');
$_SESSION['modx.user.contextTokens'] = $this->sessionContexts;
if (!isset($_SESSION["modx.{$context}.user.token"])) {
$_SESSION["modx.{$context}.user.token"] = $this->generateToken($context);
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Attempt to login to a context with an empty key", '', __METHOD__, __FILE__, __LINE__);
}
}