本文整理汇总了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');
}