本文整理汇总了PHP中Cookie::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Cookie::get方法的具体用法?PHP Cookie::get怎么用?PHP Cookie::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetData
public function testSetData()
{
$this->cookie->set('fairy', 'test');
$this->cookie->set_cookie_data(array('fairy' => 'Blum'));
$this->assertEquals(0, count($this->cookie->get_updates()));
$this->assertEquals('Blum', $this->cookie->get('fairy', 'test'));
}
示例2: add
/**
* Add a cookie to the pool.
*
* @param Cookie $cookie A cookie.
*/
public function add(Cookie $cookie)
{
if ($cookie instanceof MutableCookie) {
$this->cookies[$cookie->getName()] = $cookie;
} elseif ($cookie instanceof ResponseCookie) {
$this[$cookie->getName()]->set($cookie->get())->setPath($cookie->getPath())->setDomain($cookie->getDomain())->setSecure($cookie->isSecure())->setHttpOnly($cookie->isHttpOnly())->expiresAt($cookie->getExpiration());
} else {
$this->cookies[$cookie->getName()] = $this->setDefaults(new MutableCookie($cookie->getName(), $cookie->get()));
}
}
示例3: testGet
/**
* @runInSeparateProcess
*/
public function testGet()
{
$cookie = new Cookie();
$cookie->set('testGet');
$result = $cookie->get('openimporter_cookie');
$this->assertEquals('testGet', $result);
$cookie->set('testGet', 'another_name');
$result = $cookie->get('another_name');
$this->assertEquals('testGet', $result);
$result = $cookie->get('random');
$this->assertFalse($result);
}
示例4: __trigger
protected function __trigger()
{
$supported_language_codes = LanguageRedirect::instance()->getSupportedLanguageCodes();
// only do something when there is a set of supported languages defined
if (!empty($supported_language_codes)) {
$current_language_code = LanguageRedirect::instance()->getLanguageCode();
// no redirect, set current language and region in cookie
if (isset($current_language_code) and in_array($current_language_code, $supported_language_codes)) {
$Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'language-redirect', TWO_WEEKS, __SYM_COOKIE_PATH__);
$Cookie->set('language', LanguageRedirect::instance()->getLanguage());
$Cookie->set('region', LanguageRedirect::instance()->getRegion());
} else {
$current_path = !isset($current_language_code) ? $this->_env['param']['current-path'] : substr($this->_env['param']['current-path'], strlen($current_language_code) + 1);
$browser_languages = $this->getBrowserLanguages();
foreach ($browser_languages as $language) {
if (in_array($language, $supported_language_codes)) {
$in_browser_languages = true;
$browser_language = $language;
break;
}
}
$Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'language-redirect', TWO_WEEKS, __SYM_COOKIE_PATH__);
$cookie_language_code = $Cookie->get('language');
if (strlen($cookie_language_code) > 0) {
$language_code = $Cookie->get('region') ? $cookie_language_code . '-' . $Cookie->get('region') : $cookie_language_code;
} elseif ($in_browser_languages) {
$language_code = $browser_language;
} else {
$language_code = $supported_language_codes[0];
}
// redirect and exit
header('Location: ' . $this->_env['param']['root'] . '/' . $language_code . '/' . $current_path);
die;
}
$all_languages = LanguageRedirect::instance()->getAllLanguages();
$result = new XMLElement('language-redirect');
$current_language_xml = new XMLElement('current-language', $all_languages[$current_language_code] ? $all_languages[$current_language_code] : $current_language_code);
$current_language_xml->setAttribute('handle', $current_language_code);
$result->appendChild($current_language_xml);
$supported_languages_xml = new XMLElement('supported-languages');
foreach ($supported_language_codes as $language) {
$language_code = new XMLElement('item', $all_languages[$language] ? $all_languages[$language] : $language);
$language_code->setAttribute('handle', $language);
$supported_languages_xml->appendChild($language_code);
}
$result->appendChild($supported_languages_xml);
return $result;
}
return false;
}
示例5: Check_User_Cart
function Check_User_Cart()
{
$Identifier = '';
if (!Sentry::check()) {
return false;
} else {
$Identifier = Sentry::user()->id;
if (Cookie::has('Anon_Cart_Extension')) {
$AnonIdentifier = Cookie::get('Anon_Cart_Extension');
$dataAnon = Cache::get('user_cart.' . $AnonIdentifier);
if (Cache::has('user_cart.' . $Identifier)) {
$dataUser = Cache::get('user_cart.' . $Identifier);
if ($dataAnon != null && $dataUser != null) {
foreach ($dataAnon as $key => $value) {
if (!isset($dataUser[$key])) {
$dataUser[$key] = $value;
}
}
Cache::forever('user_cart.' . $Identifier, $dataUser);
Cache::forget('user_cart.' . $AnonIdentifier);
}
} else {
if ($dataAnon != null) {
Cache::forever('user_cart.' . $Identifier, $dataAnon);
Cache::forget('user_cart.' . $AnonIdentifier);
}
}
}
}
}
示例6: index
public function index()
{
$language = Cookie::get('language');
$this->assign('language', $language);
$this->assign('browser_id', css_browser_id());
$this->display();
}
示例7: deviceInfo
function deviceInfo()
{
$client = Client::get_instance();
// Referral
$client->referrer = Useragent::referrer();
// Heavy detections will be cached in cookie
$cookieStore = array('device', 'browser', 'browserVersion', 'os', 'country', 'city', 'lat', 'lon', 'timezone');
$device_info_cookie = Cookie::get('device_info');
if ($device_info_cookie && ($device_info_cookie = json_decode($device_info_cookie))) {
foreach ($cookieStore as $key) {
$client->{$key} = $device_info_cookie->{$key};
}
} else {
// Device and browser
// Use Mobile_Detect for better device recognition
$client->device = Useragent::is_mobile() ? 'phone' : 'computer';
$client->browser = Useragent::browser();
$client->browserVersion = Useragent::version();
$client->os = Useragent::platform();
// Geolocation
// Defaults to Kyiv
$gb = new IPGeoBase();
$geo = $gb->getRecord($client->ip);
$client->country = empty($geo['cc']) ? 'UA' : $geo['cc'];
$client->city = empty($geo['city']) ? 'Киев' : $geo['city'];
$client->lat = empty($geo['lat']) ? 50.4501 : $geo['lat'];
$client->lon = empty($geo['lon']) ? 30.5234 : $geo['lon'];
$client->timezone = empty($geo['timezone']) ? Config::get('application.timezone', 'Europe/Kiev') : $geo['timezone'];
$cookieStoreData = new \stdClass();
foreach ($cookieStore as $key) {
$cookieStoreData->{$key} = $client->{$key};
}
Cookie::make('device_info', json_encode($cookieStoreData), 60 * 60 * 4);
}
}
示例8: before
public function before()
{
parent::before();
//Visits
$visited = \Cookie::get('visited', false);
if (!$visited) {
\Dashboard::log_visitor();
\Cookie::set("visited", true, time() + 86400);
}
// Cart
\Config::load('cart', true);
$cartManager = new \Cart\Manager(\Config::get('cart'));
\CartManager::init($cartManager);
\CartManager::context('Cart');
// Set Visitors group default
\Product\Model_Attribute::set_user_group(3);
\Theme::instance()->active('frontend');
\Theme::instance()->set_template($this->template);
// Set a global variable so views can use it
$seo = array('meta_title' => '', 'meta_description' => '', 'meta_keywords' => '', 'canonical_links' => '', 'meta_robots_index' => 1, 'meta_robots_follow' => 1);
\View::set_global('seo', $seo, false);
\View::set_global('theme', \Theme::instance(), false);
\View::set_global('logged', $this->check_logged(), false);
\View::set_global('guest', $this->check_guest(), false);
\View::set_global('logged_type', $this->check_logged_type(), false);
}
示例9: autoLogin
private function autoLogin()
{
try {
if (\Session::has('userID')) {
} else {
//try set session from cookies if no session
if (!empty(\Cookie::get('userID'))) {
$field = array('field' => '_id', 'value' => (string) \Cookie::get('userID'));
if (Auth::isExists($field)) {
\Session::put('userID', \Cookie::get('userID'));
//
//return \Response::make()->withCookie(\Cookie::make('userID', \Cookie::get('userID') , self::COOKIE_EXPIRE));
} else {
throw new AuthCheckException('username', 'auth.username.doesnt.exist');
}
} else {
//\Session::forget('userID')->withCookie(\Cookie::forget('userID'))->withCookie(\Cookie::forget('userID'));
throw new AuthCheckException('userid', 'auth.userid.doesnt.exist');
}
}
} catch (Exception $e) {
$return = \Response::json(["message" => "Session logout!"], 400);
\Session::forget('userID');
return $return->withCookie(Cookie::forget('userID'))->withCookie(Cookie::forget('userID'));
}
}
示例10: setUp
public function setUp()
{
parent::setUp();
Translatable::disable_locale_filter();
//Publish all english pages
$pages = Page::get()->filter('Locale', 'en_US');
foreach ($pages as $page) {
$page->publish('Stage', 'Live');
}
//Rewrite the french translation groups and publish french pages
$pagesFR = Page::get()->filter('Locale', 'fr_FR');
foreach ($pagesFR as $index => $page) {
$page->addTranslationGroup($pages->offsetGet($index)->ID, true);
$page->publish('Stage', 'Live');
}
Translatable::enable_locale_filter();
$this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
$this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
$this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
$this->origCookieLocale = Cookie::get('language');
Cookie::force_expiry('language');
Cookie::set('language', 'en');
$this->origCurrentLocale = Translatable::get_current_locale();
Translatable::set_current_locale('en_US');
$this->origLocale = Translatable::default_locale();
Translatable::set_default_locale('en_US');
$this->origi18nLocale = i18n::get_locale();
i18n::set_locale('en_US');
$this->origAllowedLocales = Translatable::get_allowed_locales();
Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
MultilingualRootURLController::reset();
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:35,代码来源:MultilingualModelAsControllerTest.php
示例11: isLoggedIn
/**
* This function determines whether an there is a currently logged in
* Author for Symphony by using the `$Cookie`'s username
* and password. If an Author is found, they will be logged in, otherwise
* the `$Cookie` will be destroyed.
*
* @see core.Cookie#expire()
*/
public function isLoggedIn()
{
// Ensures that we're in the real world.. Also reduces three queries from database
// We must return true otherwise exceptions are not shown
if (is_null(self::$_instance)) {
return true;
}
if ($this->Author) {
return true;
} else {
$username = self::Database()->cleanValue($this->Cookie->get('username'));
$password = self::Database()->cleanValue($this->Cookie->get('pass'));
if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0) {
$author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf("\n\t\t\t\t\t\t\t`username` = '%s'\n\t\t\t\t\t\t", $username));
if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), true)) {
$this->Author = current($author);
self::Database()->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', sprintf(" `id` = %d", $this->Author->get('id')));
// Only set custom author language in the backend
if (class_exists('Administration')) {
Lang::set($this->Author->get('language'));
}
return true;
}
}
$this->Cookie->expire();
return false;
}
}
示例12: isLoggedIn
/**
* This function determines whether an there is a currently logged in
* Author for Symphony by using the `$Cookie`'s username
* and password. If an Author is found, they will be logged in, otherwise
* the `$Cookie` will be destroyed.
*
* @see core.Cookie#expire()
*/
public function isLoggedIn()
{
// Ensures that we're in the real world.. Also reduces three queries from database
// We must return true otherwise exceptions are not shown
if (is_null(self::$_instance)) {
return true;
}
if ($this->Author) {
return true;
} else {
$username = self::$Database->cleanValue($this->Cookie->get('username'));
$password = self::$Database->cleanValue($this->Cookie->get('pass'));
if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0) {
$id = self::$Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_authors` WHERE `username` = '{$username}' AND `password` = '{$password}' LIMIT 1");
if ($id) {
self::$Database->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', " `id` = '{$id}'");
$this->Author = AuthorManager::fetchByID($id);
Lang::set($this->Author->get('language'));
return true;
}
}
$this->Cookie->expire();
return false;
}
}
示例13: before
public function before()
{
if ($this->request->action === 'media') {
// Do not template media files
$this->auto_render = FALSE;
} else {
// Grab the necessary routes
$this->media = Route::get('docs/media');
$this->api = Route::get('docs/api');
$this->guide = Route::get('docs/guide');
if (isset($_GET['lang'])) {
$lang = $_GET['lang'];
// Load the accepted language list
$translations = array_keys(Kohana::message('userguide', 'translations'));
if (in_array($lang, $translations)) {
// Set the language cookie
Cookie::set('userguide_language', $lang, Date::YEAR);
}
// Reload the page
$this->request->redirect($this->request->uri);
}
// Set the translation language
I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang);
// Use customized Markdown parser
define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
// Load Markdown support
require Kohana::find_file('vendor', 'markdown/markdown');
// Set the base URL for links and images
Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/';
Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/';
}
parent::before();
}
示例14: Check
/**
* @return UserSession|bool
* @throws \Kohana_Exception
*/
public static function Check()
{
$conf = \Kohana::$config->load('session')->get('native');
$condition = (new \DBCriteria())->addColumnCondition(['ip' => \Request::$client_ip, 'iduser' => \Session::instance()->get('user_id', false), 'token' => self::getToken()])->addCondition('`expired`>=UNIX_TIMESTAMP(NOW())');
/** @var $dbSession UserSession */
$dbSession = UserSession::model()->find($condition);
//if we not found row in BD
if (is_null($dbSession)) {
return false;
}
//If session key destroy in Cookie and Session(memcahed)
if (!\Cookie::get('user_token', false) and !\Session::instance()->get('user_token', false)) {
$dbSession->expired = time() + $conf['lifetime'];
if ($dbSession->save()) {
\Session::instance()->set('user_id', $dbSession->id);
\Cookie::set('user_token', $dbSession['token'], time() + $conf['lifetime']);
\Session::instance()->set('user_token', $dbSession['token']);
return $dbSession;
//return true;
} else {
\Kohana::$log->add(\Log::WARNING, 'Error to update session in [ID#' . $dbSession->owner->login . ']');
return true;
}
} else {
if (\Cookie::get('user_token', false) !== \Session::instance()->get('user_token', false)) {
\Kohana::$log->add(\Log::WARNING, 'Session Key <> Cookie Key');
}
$expired = time() + $conf['lifetime'];
$dbSession->expired = $expired;
$dbSession->save(false);
\Cookie::set('user_token', $dbSession->token, $expired);
return $dbSession;
}
}
示例15: before
public function before()
{
parent::before();
// The user is already logged in
if (Auth::instance()->logged_in())
{
Request::instance()->redirect('');
}
// Load the configuration for this provider
$config = Kohana::config('oauth.'.$this->provider);
// Create a consumer from the config
$this->consumer = OAuth_Consumer::factory($config);
// Load the provider
$this->provider = OAuth_Provider::factory($this->provider);
if ($token = Cookie::get($this->cookie))
{
// Get the token from storage
$this->token = unserialize($token);
}
}