Search
 
SCRIPT & CODE EXAMPLE
 

PHP

yii2 get cookie

// get the cookie collection (yiiwebCookieCollection) from the "request" component
$cookies = Yii::$app->request->cookies;

// get the "language" cookie value. If the cookie does not exist, return "en" as the default value.
$language = $cookies->getValue('language', 'en');

// an alternative way of getting the "language" cookie value
if (($cookie = $cookies->get('language')) !== null) {
    $language = $cookie->value;
}

// you may also use $cookies like an array
if (isset($cookies['language'])) {
    $language = $cookies['language']->value;
}

// check if there is a "language" cookie
if ($cookies->has('language')) ...
if (isset($cookies['language'])) ...
Comment

yii2 set cookie

// get the cookie collection (yiiwebCookieCollection) from the "response" component
$cookies = Yii::$app->response->cookies;

// add a new cookie to the response to be sent
$cookies->add(new yiiwebCookie([
    'name' => 'language',
    'value' => 'zh-CN',
]));

// remove a cookie
$cookies->remove('language');
// equivalent to the following
unset($cookies['language']);
Comment

PREVIOUS NEXT
Code Example
Php :: php text Cyrillic check 
Php :: php pass a variabele to js 
Php :: types of looping directives in laravel 
Php :: echo post content by slug 
Php :: foreach skip first php 
Php :: laravel sentence word count 
Php :: collection continue in laravel 
Php :: php create Hmac sha256 
Php :: laravel 5.4 forelse 
Php :: drupal 7 entity_metadata_wrapper bundle 
Php :: contact form 7 select disabled option 
Php :: laravel eloquent sum column 
Php :: php 7.4 extension sqlite ubuntu 
Php :: php salto de linea 
Php :: DB::beginTransaction() 
Php :: php convert link to embed youtube 
Php :: laravel blade @guest 
Php :: php get php.ini location from termina 
Php :: php artisan services 
Php :: vue mouseover 
Php :: clear laravel cache 
Php :: jquery ajax 500 internal server error php 
Php :: prestashop get all products 
Php :: closing a php 
Php :: add new column in existing table in laravel migration 
Php :: laravel if file is image 
Php :: php count array elements with specific key 
Php :: how to reverse fetch assoc in php 
Php :: php rename files in directory 
Php :: php artisan route:list for specific name 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =