user->isGuest;" statement to determine. If the condition is true, it means that the user is not logged in."/> user->isGuest;" statement to determine. If the condition is true, it means that the user is not logged in.">
Home > Article > PHP Framework > How to determine whether to log in using yii
Determine whether the user is logged in: (Recommended learning: yii framework)
In Yii2.0, to determine whether the user is logged in, we use The following code can
Yii::$app->user->isGuest;
Example: If the user is already logged in, directly call the goHome() method
if (!\Yii::$app->user->isGuest) { return $this->goHome(); }
Get the login username
In yii2.0, get the login For the user name in the status, you can use the following code.
Yii::$app->user->identity->username;
The above is the detailed content of How to determine whether to log in using yii. For more information, please follow other related articles on the PHP Chinese website!