yii2開啟session (建議學習中:yii教學#
use yii\web\Session; $session = Yii::$app->session; // check if a session is already open if ($session->isActive) ... // open a session $session->open(); // close a session $session->close(); // destroys all data registered to a session. $session->destroy();
讀取session
$session = Yii::$app->session; $session->set('user_id', '1234'); //OR $session['user_id'] = '1234'; //OR $_SESSION['user_id'] = '1234';
銷毀session
$session = Yii::$app->session; $user_id = $session->get('user_id'); //OR $user_id = $session['user_id']; //OR $user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
以上是yii2 如何開啟session的詳細內容。更多資訊請關注PHP中文網其他相關文章!