Skip to content
  • Home
  • Blog
    • yttags
    • Youtube
  • Categories
  • Tools
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
  • JS
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us
Pakainfo

Pakainfo

Web Development & Good Online education

Session Management Using Yii Framework

July 14, 2018 Pakainfo Programming, Yii Leave a comment
Rate this post

Session Management Using Yii Framework

Today, We want to share with you Session Management Using Yii Framework.
In this post we will show you Session Management Using Yii Framework, hear for Session Management with the Yii Framework we will give you demo and example for implement.
In this post, we will learn about The Yii Framework Session Management Basics with an example.

Session Handling In Yii Framework 2.0

The Session Handling is the most part in Server In Yii Framework 2.0. A session store is a way to store value information to be used across used to multiple pages for individual check users request. In plain PHP like as a , we can every access the session store through the global variables used to $_SESSION.

Read Also:  Vue JS - Get Query String Value Example

How to handle session in yii2 steps

  • Opening and Closing Sessions in yii
  • Set Session Variable in yii
  • Get Session Variable in yii
  • Remove Session Variable in yii
  • Check Session Variable Available Or Not in yii
  • List All Session Variable in yii
  • Arrays Of Session in yii
  • Flash Data Using Session in yii

Opening and Closing Sessions In Yii

use  yii\web\Session;
$session = Yii::$app->session;
if ($session->isActive) ...
$session->open();
$session->close();
$session->destroy();

Set Session Variable

$session = Yii::$app->session;
$session->set('user_id', '1234');
$session['user_id'] = '1234';
$_SESSION['user_id'] = '1234';

Get Session Variable

$session = Yii::$app->session;
$user_id = $session->get('user_id');
$user_id = $session['user_id'];
$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;

Remove Session Variable

$session = Yii::$app->session;
$session->remove('user_id');
unset($session['user_id']);
unset($_SESSION['user_id']);

Check Session Variable Available Or Not

if ($session->has('user_id')) ...
//OR like
if (isset($session['user_id'])) ...
//OR like
if (isset($_SESSION['user_id'])) .

List All Session Variable

foreach ($session as $session_name => $session_value)
	echo $session_name.' - '.$session_value;
//OR like as a
foreach ($_SESSION as $session_name => $session_value)
	echo $session_name.' - '.$session_value;

Arrays Of Session

$session = Yii::$app->session;
$session['user'] = [
    'id' => 1,
    'username' => 'yiiuser',
];
echo $session['user']['id'];
echo $session['user']['username'];

$session['user.id'] = 1;
$session['user.username'] = 'yiiuser';

Flash Data Using Session

$session = Yii::$app->session;
$session->setFlash('userinsert', 'You have successfully registered.');
$result = $session->hasFlash('userinsert');
echo $session->getFlash('userinsert');

Global session variable under the used to app() variable. and we can store values

Yii::app()->session['sleep'] = "value";

Free Live Chat for Any Issue

Get values

$sleep = Yii::app()->session['sleep'];

remove values

unset(Yii::app()->session['sleep']);

Download the Yii Framework

Download

Download

Read Also:  Create Dynamic XML Sitemaps Using PHP MYSQL

Related posts:

  1. HTTP Session Management Using Laravel
  2. PHP Secure Session Management System
  3. Session Management in CodeIgniter with PHP
  4. PHP Laravel framework session Example
  5. Get PHP Session Value using AJAX/Jquery
  6. PHP login logout script with session Example
  7. How To Create Image Hover Overlay Effects?
  8. Codeigniter Session set and Retrieve multidimensional array
  9. Multiple image slider in html source code
  10. how to set session value in javascript PHP?
Read Also:  Load web pages iframe using jQuery Example
how to use session in yii2yii::app()->sessionyii2 session arrayyii2 session configyii2 session databaseyii2 session timeoutyii2 set cookieyii2 set session after login

Post navigation

Previous Post:How to Configure Virtual Host in XAMPP
Next Post:Top 10 Yii Interview Questions and Answers for fresher

Search

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me
Cricday

Categories

3movierulz (48) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (92) Codeigniter (174) CSS (96) Earn Money (61) Education (53) Entertainment (108) fullform (77) Google Adsense (62) Highcharts (77) Hollywood (93) JavaScript (1354) Jobs (39) jQuery (1421) Laravel (1083) LifeStyle (50) movierulz4 (47) Mysql (1029) Mysqli (890) Node.js (38) php (2110) Programming (2320) Python (96) ReactJS (37) Software (102) Software (77) Stories (78) tamilrockers (88) Tamilrockers kannada (48) Tamilrockers telugu (47) Tech (102) Technology (2359) Tips and Tricks (107) Tools (112) Top10 (295) Trading (50) Trending (45) VueJs (250) Web Technology (83) webtools (129) wordpress (165) World (123)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here

Web Development & Good Online education : Pakainfo by Pakainfo.
Top
Subscribe On YouTube : Download Source Code & New itsolutionstuck
We accept paid guest Posting on our Site : Guest Post Chat with Us On WhatsApp