Skip to content

Kirby 5.0.0

$user->login()

Logs the user in

$user->login(string $password, Kirby\Session\Session|array|null $session = null): bool

Parameters

Name Type Default Description
$passwordrequired string no default value
$session Kirby\Session\Sessionorarrayornull null Session options or session object to set the user in

Return type

bool

Parent class

Kirby\Cms\User

Examples

// simple login form submission example
if ($username = get('username') and $password = get('password')) {

  $user = $kirby->user($username);

  if ($user and $user->login($password)) {
    // redirect to the homepage
    // or any other page
    go();
  } else {
    echo 'invalid username or password';
  }

}

// put the login form with username and
// password field down here.