本文整理汇总了PHP中WebRequest::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP WebRequest::setCookie方法的具体用法?PHP WebRequest::setCookie怎么用?PHP WebRequest::setCookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebRequest
的用法示例。
在下文中一共展示了WebRequest::setCookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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";
}