PHPackages                             webiik/login - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. webiik/login

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

webiik/login
============

The Login manages the user login state.

1.1(5y ago)126MITPHPPHP &gt;=7.2

Since Mar 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/webiik/login)[ Packagist](https://packagist.org/packages/webiik/login)[ Docs](https://www.webiik.com)[ RSS](/packages/webiik-login/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

[![](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)[![](https://camo.githubusercontent.com/4d4ca836ca9a7ada0e1af9ad063ecd0969e39a62186423a005bd590ddae3255d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d332d627269676874677265656e2e737667)](https://camo.githubusercontent.com/4d4ca836ca9a7ada0e1af9ad063ecd0969e39a62186423a005bd590ddae3255d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d332d627269676874677265656e2e737667)

Login
=====

[](#login)

The Login manages the user login state. It supports:

- permanent login
- automatic logout
- login namespaces

> **Note:** This class is meant to be used after the successful user authentication and authorization.

Installation
------------

[](#installation)

```
composer require webiik/login
```

Example
-------

[](#example)

```
$login = new \Webiik\Login\Login($token, $cookie, $session);

// Log-in the user with id 1
$login->login(1);

// Check if the user is logged in
if ($login->isLogged()) {
    echo 'The user id ' . $login->getUserId() . ' is logged.';
} else {
    echo 'The user is not logged.';
}

// Log the user out
$login->logout();
```

Summary
-------

[](#summary)

- [Basic Login](#basic-login)
- [Permanent Login](#permanent-login)
- [Login Check](#login-check)
- [Logout](#logout)

Basic Login
-----------

[](#basic-login)

### setSessionKey

[](#setsessionkey)

```
setSessionKey(string $sessionKey): void
```

**setSessionKey()** sets the key of login state stored in PHP session. This key holds the [**uid**](#login) value. The default value of the key is **logged**.

```
$login->setSessionName('logged');
```

### setNamespace

[](#setnamespace)

```
setNamespace(string $name): void
```

**setNamespace()** sets login namespace. If you want to make the login valid only for the specific part of your app, use the login namespace. Imagine you have a multilingual app and you want to make a separate account for every language - this is the situation when the login namespace can help.

```
$login->setNamespace('en');
```

### login

[](#login-1)

```
login($uid, bool $permanent = false): void
```

**login()** logs the user in. Login() writes login state to PHP session. If permanent login is not set, login is valid until the user closes the browser or the [PHP session](https://github.com/webiik/webiik/blob/master/src/Webiik/Session/README.md) expires.

**Parameters**

- **uid** user unique identifier to be stored in PHP session
- **permanent** indicates if to use permanent login. Read more in [permanent login](#permanent-login) section.

```
// Log in the user with id 1
$login->login(1);
```

```
// Permanently log in the user with id 1
$login->login(1, true);
```

Permanent Login
---------------

[](#permanent-login)

### setPermanentCookieName

[](#setpermanentcookiename)

```
setPermanentCookieName(string $name): void
```

**setPermanentCookieName()** sets the name of cookie where the permanent login information is stored at the users' computer. The default value is **PC**.

```
$login->setPermanentCookieName('PC');
```

### setPermanentLoginStorage

[](#setpermanentloginstorage)

> **Note:** To start using the permanent login, it's required to set permanent login storage.

```
setPermanentLoginStorage(callable $factory, int $days = 30): void
```

**setPermanentLoginStorage()** sets the factory of permanent login storage and the time validity of permanent login data.

**Parameters**

- **factory** factory creates object implementing **[StorageInterface](Storage/StorageInterface.php)**
- **days** how many days to keep permanent cookie and data in storage when user is not active

Permanent login saves the permanent login data to the user's computer (cookie) and to the server. Storage is here to solve the server part and to make storing data flexible. Out of the box, the Login class comes with the [FileStorage](Storage/FileStorage.php), it saves login information to the disk at the server. However, you can write your own storage.

Example of using the file storage:

```
$login->setPermanentLoginStorage(function () {
    $fs = new \Webiik\Login\Storage\FileStorage();
    $fs->setPath(__DIR__ . '/tmp/permanent');
    return $fs;
});
```

**Write Custom Storage**

You can write your custom storage. Only thing you have to do is to implement **[StorageInterface](Storage/StorageInterface.php)**.

Login Check
-----------

[](#login-check)

### isLogged

[](#islogged)

```
isLogged(): bool
```

**isLogged()** checks if user is logged in.

```
if ($login->isLogged()) {
    echo 'The user id ' . $login->getUserId() . ' is logged.';
} else {
    echo 'The user is not logged.';
}
```

Logout
------

[](#logout)

### logout

[](#logout-1)

```
logout(): void
```

**logout()** logs the user out.

```
$login->logout();
```

### setAutoLogoutTime

[](#setautologouttime)

```
setAutoLogoutTime(int $sec): void
```

**setAutoLogoutTime()** sets the time in seconds to auto logout the user on inactivity between two requests. The default value is 0 - no automatic logout. Automatic logout is ignored when user is logged permanently.

```
// Set the automatic logout after 5 minutes of inactivity between two requests
$login->setAutoLogoutTime(5 * 60);
```

**Warning:** [Update the time](#updateautologoutts) of last user activity with every http request to make auto logout feature working properly.

### updateAutoLogoutTs

[](#updateautologoutts)

```
updateAutoLogoutTs(): void
```

**updateAutoLogoutTs()** updates time of last users' activity stored in the session.

```
// Never call this before isLogged, it would lead
// to the situation, that the user was never logged out
$login->updateAutoLogoutTs();
```

### getLogoutReason

[](#getlogoutreason)

```
getLogoutReason(): void
```

**getLogoutReason()** returns logout reason.

```
if ($login->getLogoutReason() == $login::MANUAL) {
    // manual logout
} elseif ($login->getLogoutReason() == $login::AUTO) {
    // auto logout due inactivity
}
```

Resources
---------

[](#resources)

- [Webiik framework](https://github.com/webiik/webiik)
- [Report issue](https://github.com/webiik/components/issues)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~507 days

Total

2

Last Release

2097d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1226362d003d186b45e7dfa44489c36af37196c6a1b476206700eaf4e9c96a5a?d=identicon)[Jiri Mihal](/maintainers/Jiri%20Mihal)

---

Top Contributors

[![Jiri-Mihal](https://avatars.githubusercontent.com/u/10408123?v=4)](https://github.com/Jiri-Mihal "Jiri-Mihal (223 commits)")

---

Tags

authAuthenticationauthorisationlogin

### Embed Badge

![Health badge](/badges/webiik-login/health.svg)

```
[![Health](https://phpackages.com/badges/webiik-login/health.svg)](https://phpackages.com/packages/webiik-login)
```

###  Alternatives

[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M248](/packages/league-oauth2-server)[auth0/auth0-php

PHP SDK for Auth0 Authentication and Management APIs.

40820.2M68](/packages/auth0-auth0-php)[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[delight-im/auth

Authentication for PHP. Simple, lightweight and secure.

1.3k135.7k20](/packages/delight-im-auth)[auth0/symfony

Symfony SDK for Auth0 Authentication and Management APIs.

128738.1k](/packages/auth0-symfony)[auth0/wordpress

WordPress Plugin for Auth0

17419.5k](/packages/auth0-wordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
