web\User login()

login() public method

Logs in a user.

After logging in a user, you may obtain the user's identity information from the $identity property. If $enableSession is true, you may even get the identity information in the next requests without calling this method again.

The login status is maintained according to the $duration parameter:

  • $duration == 0: the identity information will be stored in session and will be available via $identity as long as the session remains active.
  • $duration > 0: the identity information will be stored in session. If $enableAutoLogin is true, it will also be stored in a cookie which will expire in $duration seconds. As long as the cookie remains valid or the session is active, you may obtain the user identity information via $identity.

Note that if $enableSession is false, the $duration parameter will be ignored as it is meaningless in this case.

public boolean login ( yii\web\IdentityInterface $identity, $duration = 0 )
$identity yii\web\IdentityInterface

The user identity (which should already be authenticated)

$duration integer

Number of seconds that the user can remain in logged-in status. Defaults to 0, meaning login till the user closes the browser or the session is manually destroyed. If greater than 0 and $enableAutoLogin is true, cookie-based login will be supported. Note that if $enableSession is false, this parameter will be ignored.

return boolean

Whether the user is logged in

doc_Yii
2016-10-30 17:17:22
Comments
Leave a Comment

Please login to continue.