本文整理汇总了PHP中SimpleSAML\Utils\HTTP::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::setCookie方法的具体用法?PHP HTTP::setCookie怎么用?PHP HTTP::setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleSAML\Utils\HTTP
的用法示例。
在下文中一共展示了HTTP::setCookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPreviousSource
/**
* Set the previous authentication source.
*
* This method remembers the authentication source that the user selected
* by storing its name in a cookie.
*
* @param string $source Name of the authentication source the user selected.
*/
public function setPreviousSource($source)
{
assert('is_string($source)');
$cookieName = 'multiauth_source_' . $this->authId;
$config = SimpleSAML_Configuration::getInstance();
$params = array('lifetime' => 60 * 60 * 24 * 90, 'path' => $config->getBasePath(), 'httponly' => FALSE);
\SimpleSAML\Utils\HTTP::setCookie($cookieName, $source, $params, FALSE);
}
示例2: time
} else {
$password = '';
}
$errorCode = NULL;
$errorParams = NULL;
if (!empty($_REQUEST['username']) || !empty($password)) {
// Either username or password set - attempt to log in
if (array_key_exists('forcedUsername', $state)) {
$username = $state['forcedUsername'];
}
if ($source->getRememberUsernameEnabled()) {
$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
$params = $sessionHandler->getCookieParams();
$params['expire'] = time();
$params['expire'] += isset($_REQUEST['remember_username']) && $_REQUEST['remember_username'] == 'Yes' ? 31536000 : -300;
\SimpleSAML\Utils\HTTP::setCookie($source->getAuthId() . '-username', $username, $params, FALSE);
}
if ($source->isRememberMeEnabled()) {
if (array_key_exists('remember_me', $_REQUEST) && $_REQUEST['remember_me'] === 'Yes') {
$state['RememberMe'] = TRUE;
$authStateId = SimpleSAML_Auth_State::saveState($state, sspmod_core_Auth_UserPassBase::STAGEID);
}
}
try {
sspmod_core_Auth_UserPassBase::handleLogin($authStateId, $username, $password);
} catch (SimpleSAML_Error_Error $e) {
/* Login failed. Extract error code and parameters, to display the error. */
$errorCode = $e->getErrorCode();
$errorParams = $e->getParameters();
}
}
示例3: array
<?php
/**
*
*
* @author Mathias Meisfjordskar, University of Oslo.
* <mathias.meisfjordskar@usit.uio.no>
* @package SimpleSAMLphp
*/
$params = array('expire' => mktime(0, 0, 0, 1, 1, 2038), 'secure' => FALSE, 'httponly' => TRUE);
\SimpleSAML\Utils\HTTP::setCookie('NEGOTIATE_AUTOLOGIN_DISABLE_PERMANENT', 'True', $params, FALSE);
$globalConfig = SimpleSAML_Configuration::getInstance();
$session = SimpleSAML_Session::getSessionFromRequest();
$session->setData('negotiate:disable', 'session', FALSE, 24 * 60 * 60);
$t = new SimpleSAML_XHTML_Template($globalConfig, 'negotiate:disable.php');
$t->show();
示例4: setPreviousIdP
/**
* Save the current IdP choice to a cookie.
*
* This function overrides the corresponding function in the parent class, to add support for common domain cookie.
*
* @param string $idp The entityID of the IdP.
*/
protected function setPreviousIdP($idp)
{
assert('is_string($idp)');
if ($this->cdcDomain === null) {
parent::setPreviousIdP($idp);
return;
}
$list = $this->getCDC();
$prevIndex = array_search($idp, $list, true);
if ($prevIndex !== false) {
unset($list[$prevIndex]);
}
$list[] = $idp;
foreach ($list as &$value) {
$value = base64_encode($value);
}
$newCookie = implode(' ', $list);
while (strlen($newCookie) > 4000) {
// the cookie is too long. Remove the oldest elements until it is short enough
$tmp = explode(' ', $newCookie, 2);
if (count($tmp) === 1) {
// we are left with a single entityID whose base64 representation is too long to fit in a cookie
break;
}
$newCookie = $tmp[1];
}
$params = array('lifetime' => $this->cdcLifetime, 'domain' => $this->cdcDomain, 'secure' => true, 'httponly' => false);
\SimpleSAML\Utils\HTTP::setCookie('_saml_idp', $newCookie, $params, false);
}
示例5: updateSessionCookies
/**
* Update session cookies.
*
* @param array $params The parameters for the cookies.
*/
public function updateSessionCookies($params = null)
{
$sessionHandler = SimpleSAML_SessionHandler::getSessionHandler();
if ($this->sessionId !== null) {
$sessionHandler->setCookie($sessionHandler->getSessionCookieName(), $this->sessionId, $params);
}
if ($this->authToken !== null) {
$globalConfig = SimpleSAML_Configuration::getInstance();
\SimpleSAML\Utils\HTTP::setCookie($globalConfig->getString('session.authtoken.cookiename', 'SimpleSAMLAuthToken'), $this->authToken, $params);
}
}
示例6: setCookie
/**
* Save cookie with the given name and value.
*
* This function will save a cookie with the given name and value for the current discovery
* service type.
*
* @param string $name The name of the cookie.
* @param string $value The value of the cookie.
*/
protected function setCookie($name, $value)
{
$prefixedName = 'idpdisco_' . $this->instance . '_' . $name;
$params = array('lifetime' => 60 * 60 * 24 * 90, 'path' => '/' . $this->config->getBaseUrl(), 'httponly' => false);
\SimpleSAML\Utils\HTTP::setCookie($prefixedName, $value, $params, false);
}
示例7: setCDC
/**
* Build a CDC cookie string.
*
* @param array $list The list of IdPs.
* @return string The CDC cookie value.
*/
function setCDC(array $list)
{
foreach ($list as &$value) {
$value = base64_encode($value);
}
$cookie = implode(' ', $list);
while (strlen($cookie) > 4000) {
/* The cookie is too long. Remove the oldest elements until it is short enough. */
$tmp = explode(' ', $cookie, 2);
if (count($tmp) === 1) {
/*
* We are left with a single entityID whose base64
* representation is too long to fit in a cookie.
*/
break;
}
$cookie = $tmp[1];
}
$params = array('lifetime' => $this->cookieLifetime, 'path' => '/', 'domain' => '.' . $this->domain, 'secure' => TRUE, 'httponly' => FALSE);
\SimpleSAML\Utils\HTTP::setCookie('_saml_idp', $cookie, $params, FALSE);
}
示例8: setLanguageCookie
/**
* This method will attempt to set the user-selected language in a cookie. It will do nothing if the language
* specified is not in the list of available languages, or the headers have already been sent to the browser.
*
* @param string $language The language set by the user.
*/
public static function setLanguageCookie($language)
{
assert('is_string($language)');
$language = strtolower($language);
$config = \SimpleSAML_Configuration::getInstance();
$availableLanguages = $config->getArray('language.available', array('en'));
if (!in_array($language, $availableLanguages, true) || headers_sent()) {
return;
}
$name = $config->getString('language.cookie.name', 'language');
$params = array('lifetime' => $config->getInteger('language.cookie.lifetime', 60 * 60 * 24 * 900), 'domain' => $config->getString('language.cookie.domain', null), 'path' => $config->getString('language.cookie.path', '/'), 'httponly' => false);
HTTP::setCookie($name, $language, $params, false);
}
示例9: setCookie
/**
* @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::setCookie() instead.
*/
public static function setCookie($name, $value, array $params = NULL, $throw = TRUE)
{
\SimpleSAML\Utils\HTTP::setCookie($name, $value, $params, $throw);
}
示例10: doLogout
/**
* This function logs the user out by deleting the session information from memcache.
*/
private function doLogout()
{
$cookieName = $this->getCookieName();
// check if we have a valid cookie
if (!array_key_exists($cookieName, $_COOKIE)) {
return;
}
$sessionID = $_COOKIE[$cookieName];
// delete the session from memcache
$memcache = $this->getMemcache();
$memcache->delete($sessionID);
// delete the session cookie
\SimpleSAML\Utils\HTTP::setCookie($cookieName, null);
}
示例11: foreach
<?php
require_once '_include.php';
/**
* This page clears the user's IdP discovery choices.
*/
// The base path for cookies. This should be the installation directory for SimpleSAMLphp.
$config = SimpleSAML_Configuration::getInstance();
$cookiePath = '/' . $config->getBaseUrl();
// We delete all cookies which starts with 'idpdisco_'
foreach ($_COOKIE as $cookieName => $value) {
if (substr($cookieName, 0, 9) !== 'idpdisco_') {
/* Not a idpdisco cookie. */
continue;
}
/* Delete the cookie. We delete it once without the secure flag and once with the secure flag. This
* ensures that the cookie will be deleted in any case.
*/
\SimpleSAML\Utils\HTTP::setCookie($cookieName, NULL, array('path' => $cookiePath, 'httponly' => FALSE), FALSE);
}
/* Find where we should go now. */
if (array_key_exists('ReturnTo', $_REQUEST)) {
$returnTo = \SimpleSAML\Utils\HTTP::checkURLAllowed($_REQUEST['ReturnTo']);
} else {
/* Return to the front page if no other destination is given. This is the same as the base cookie path. */
$returnTo = $cookiePath;
}
/* Redirect to destination. */
\SimpleSAML\Utils\HTTP::redirectTrustedURL($returnTo);
示例12: _setConsentCookie
/**
* Helper function for setting a cookie.
*
* @param string $name Name of the cookie.
* @param string|null $value Value of the cookie. Set this to null to delete the cookie.
*
* @return void
*/
private function _setConsentCookie($name, $value)
{
assert('is_string($name)');
assert('is_string($value) || is_null($value)');
$globalConfig = SimpleSAML_Configuration::getInstance();
$params = array('lifetime' => 90 * 24 * 60 * 60, 'path' => $globalConfig->getBasePath(), 'httponly' => false);
if (\SimpleSAML\Utils\HTTP::isHTTPS()) {
// Enable secure cookie for https-requests
$params['secure'] = true;
} else {
$params['secure'] = false;
}
\SimpleSAML\Utils\HTTP::setCookie($name, $value, $params, false);
}
示例13: setCookie
/**
* Set a session cookie.
*
* @param string $name The name of the session cookie.
* @param string|null $value The value of the cookie. Set to null to delete the cookie.
* @param array|null $params Additional params to use for the session cookie.
*/
public function setCookie($name, $value, array $params = null)
{
assert('is_string($name)');
assert('is_string($value) || is_null($value)');
if ($params !== null) {
$params = array_merge($this->getCookieParams(), $params);
} else {
$params = $this->getCookieParams();
}
\SimpleSAML\Utils\HTTP::setCookie($name, $value, $params);
}
示例14: SimpleSAML_Auth_Simple
*
* The file extra/auth_memcookie.conf contains an example of how Auth Memcookie can be configured
* to use SimpleSAMLphp.
*/
// load SimpleSAMLphp configuration
$ssp_cf = \SimpleSAML_Configuration::getInstance();
// load Auth MemCookie configuration
$amc_cf = AuthMemCookie::getInstance();
$sourceId = $amc_cf->getAuthSource();
$s = new SimpleSAML_Auth_Simple($sourceId);
// check if the user is authorized. We attempt to authenticate the user if not
$s->requireAuth();
// generate session id and save it in a cookie
$sessionID = Utils\Random::generateID();
$cookieName = $amc_cf->getCookieName();
\SimpleSAML\Utils\HTTP::setCookie($cookieName, $sessionID);
// generate the authentication information
$attributes = $s->getAttributes();
$authData = array();
// username
$usernameAttr = $amc_cf->getUsernameAttr();
if (!array_key_exists($usernameAttr, $attributes)) {
throw new SimpleSAML_Error_Exception("The user doesn't have an attribute named '" . $usernameAttr . "'. This attribute is expected to contain the username.");
}
$authData['UserName'] = $attributes[$usernameAttr];
// groups
$groupsAttr = $amc_cf->getGroupsAttr();
if ($groupsAttr !== null) {
if (!array_key_exists($groupsAttr, $attributes)) {
throw new SimpleSAML_Error_Exception("The user doesn't have an attribute named '" . $groupsAttr . "'. This attribute is expected to contain the groups the user is a member of.");
}
示例15: setCookie
/**
* Set a session cookie.
*
* @param string $sessionName The name of the session.
* @param string|null $sessionID The session ID to use. Set to null to delete the cookie.
* @param array|null $cookieParams Additional parameters to use for the session cookie.
*
* @throws \SimpleSAML\Error\CannotSetCookie If we can't set the cookie.
*/
public function setCookie($sessionName, $sessionID, array $cookieParams = null)
{
assert('is_string($sessionName)');
assert('is_string($sessionID) || is_null($sessionID)');
if ($cookieParams !== null) {
$params = array_merge($this->getCookieParams(), $cookieParams);
} else {
$params = $this->getCookieParams();
}
\SimpleSAML\Utils\HTTP::setCookie($sessionName, $sessionID, $params, true);
}