本文整理匯總了PHP中WebRequest::getCookie方法的典型用法代碼示例。如果您正苦於以下問題:PHP WebRequest::getCookie方法的具體用法?PHP WebRequest::getCookie怎麽用?PHP WebRequest::getCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WebRequest
的用法示例。
在下文中一共展示了WebRequest::getCookie方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAccessToken
/**
* Extracts access token from HTTP request data.
*
* @param \WebRequest $request the HTTP request data as an object
* @return String access token or null
*/
public static function getAccessToken(\WebRequest $request)
{
// A cookie takes precedence over an HTTP header.
$token = $request->getCookie(self::ACCESS_TOKEN_COOKIE_NAME, '');
// No access token in the cookie, try the HTTP header.
if (!$token) {
$header = $request->getHeader('AUTHORIZATION');
$matches = [];
preg_match('/^Bearer\\s*(\\S*)$/', $header, $matches);
if (!empty($matches[1])) {
$token = $matches[1];
}
}
// Normalize the value so the method returns a non-empty string or null.
if (empty($token)) {
return null;
}
return $token;
}
示例2: getCookie
/**
* Get a cookie. Contains an auth-specific hack.
* @param \WebRequest $request
* @param string $key
* @param string $prefix
* @param mixed $default
* @return mixed
*/
protected function getCookie($request, $key, $prefix, $default = null)
{
$value = $request->getCookie($key, $prefix, $default);
if ($value === 'deleted') {
// PHP uses this value when deleting cookies. A legitimate cookie will never have
// this value (usernames start with uppercase, token is longer, other auth cookies
// are booleans or integers). Seeing this means that in a previous request we told the
// client to delete the cookie, but it has poor cookie handling. Pretend the cookie is
// not there to avoid invalidating the session.
return null;
}
return $value;
}
示例3: getActiveLanguage
public static function getActiveLanguage()
{
global $cAvailableLanguages;
// look in the order of most volatile first - if we find something, use it.
// request cache
if (self::$requestLanguage != "") {
return self::$requestLanguage;
}
// get parameter
$getParam = WebRequest::get("lang");
if ($getParam != false) {
// check value is in list of allowed values
if (array_key_exists($getParam, $cAvailableLanguages)) {
// save local cache for other messages this request
self::$requestLanguage = $getParam;
// set a cookie to persist that option for this session (do we want
// this option to set the preferences too?)
WebRequest::setCookie("lang", $getParam);
// use this value.
return $getParam;
}
}
// cookie
$cookie = WebRequest::getCookie("lang");
if ($cookie != false) {
// check value is in list of allowed values
if (array_key_exists($cookie, $cAvailableLanguages)) {
// save local cache for other messages this request
self::$requestLanguage = $cookie;
// use this value.
return $cookie;
}
}
// user preference
// site default
return "en-GB";
}
示例4: isBeta
public static function isBeta(WebRequest $request)
{
$tux = $request->getVal('tux', null);
if ($tux === null) {
$tux = $request->getCookie('tux', null, true);
} elseif ($tux) {
$request->response()->setCookie('tux', 1);
} else {
$request->response()->setCookie('tux', 0);
}
return $tux;
}
示例5: suggestLoginUsername
public function suggestLoginUsername(WebRequest $request)
{
return $request->getCookie('UserName');
}