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 :: get text field value in php 
Php :: wp_query order by taxonomy 
Php :: Pass all data to all pages laravel 
Php :: array unique php 
Php :: valet switch php version 
Php :: current time input field in laravel form 
Php :: alerta con php 
Php :: php import script 
Php :: how to retrieve data from database using select option in laravel 
Php :: acf get field 
Php :: delete directory from laravel storage 
Php :: for each php 
Php :: how to use plugin shortcode in wordpress template 
Php :: create function parameters php 
Php :: php exec without waiting 
Php :: php catch all exceptions 
Php :: laravel date format 
Php :: sum of the array elements in php 
Php :: laravel password encryption 
Php :: how to change taxonomy slug in wordpress 
Php :: PHP validation/regex for URL 
Php :: validation in laravel 
Php :: php save array in mysql database 
Php :: change the php version in linux 
Php :: laravel throw function 
Php :: How to Show the Logged in Username in the WordPress 
Php :: How to get route parameter in blade? 
Php :: php convert string to chars 
Php :: create if not exist laravel 
Php :: laravel use function from another controller 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =