use yii\web\Session;
$session = Yii::$app->session;
$session->open(); // open a session
$session->close(); // close a session
$session = Yii::$app->session;
$session->set('name', 'stack');
OR
$session['name'] = 'stack';
OR
$_SESSION['name'] = 'stack';
$name = $session->get('name');
OR
$name = $session['name'];
$session->remove('name');
OR
unset($session['name']);
OR
unset($_SESSION['name']);
$session->destroy(); // destroy all session
$session->removeAll();
$session->has('name')
OR
isset($session['name'])
//both function return boolean value [true or false]
Set session flash
$session = Yii::$app->session;
$session->setFlash('error', 'Error in login');
Get session flash
echo $session->getFlash('error');
Check session flash
$result = $session->hasFlash('error');
Remove session flash
$session->removeFlash('error');
Remove all session flash variables
$session->removeAllFlashes();
Set and get session variable
\Yii::$app->session->set('name','stack');
\Yii::$app->session->get('name');
Session flash
\Yii::$app->getSession()->setFlash('flash_msg','Message');
\Yii::$app->getSession()->getFlash('flash_msg');