PHPackages                             klevze/online-users - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. klevze/online-users

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

klevze/online-users
===================

Display online users on a webpage

v1.2.0(6mo ago)177MITPHPPHP &gt;=8.1CI passing

Since Jan 11Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/klevze/online-users)[ Packagist](https://packagist.org/packages/klevze/online-users)[ Docs](https://github.com/klevze/online-users)[ RSS](/packages/klevze-online-users/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (5)Used By (0)

Laravel plugin for displaying online users on a webpage
=======================================================

[](#laravel-plugin-for-displaying-online-users-on-a-webpage)

[![Online Users](assets/card.png)](assets/card.png)

You can also set these variables in your `.env` file (example below).

[![Latest Version on Packagist](https://camo.githubusercontent.com/6cc8a8dd0007f5e561d554935a508b5abfc3cb7570fcbef2bf9e5ac583ab8775/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6c65767a652f6f6e6c696e652d75736572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/klevze/online-users)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0fdf12423bf163ed25a703fb517f73cf718fabd906bb1daff8ebd58503709878/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c65767a652f6f6e6c696e652d75736572732f72756e2d74657374732d6c61726176656c2d31322e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/klevze/online-users/actions?query=workflow%3Arun-tests-laravel-12+branch%3Amain)

[![Laravel 12](https://camo.githubusercontent.com/5336afb51205aa175c28f15fa8b1429281ff70473f0f49153e97d09f83290a27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c65767a652f6f6e6c696e652d75736572732f72756e2d74657374732d6c61726176656c2d31322e796d6c3f6272616e63683d6d61696e266c6162656c3d4c61726176656c2532303132267374796c653d666c61742d737175617265)](https://github.com/klevze/online-users/actions?query=workflow%3Arun-tests-laravel-12+branch%3Amain)[![Laravel 12](https://camo.githubusercontent.com/5336afb51205aa175c28f15fa8b1429281ff70473f0f49153e97d09f83290a27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c65767a652f6f6e6c696e652d75736572732f72756e2d74657374732d6c61726176656c2d31322e796d6c3f6272616e63683d6d61696e266c6162656c3d4c61726176656c2532303132267374796c653d666c61742d737175617265)](https://github.com/klevze/online-users/actions?query=workflow%3Arun-tests-laravel-12+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a120ce56aea5b9a989fb4339f95918fe97f41491cae273644bad04e9c07704e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c65767a652f6f6e6c696e652d75736572732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/klevze/online-users/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/64b4c771da98f8c1e8d1d211e6369676e83001b4f6d2a8a78dd02fbdd0bb6365/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6c65767a652f6f6e6c696e652d75736572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/klevze/online-users)

> Note: This repository currently runs CI only for Laravel 12. The older per-version workflow files for Laravel 10 and 11 were removed to simplify the workflow matrix and remove duplicate CI runs. If you need per-Laravel-version badges again, recreate the per-version workflows or restore `run-tests-laravel-10.yml` and `run-tests-laravel-11.yml`.

"Online Users" is a Laravel package designed to effortlessly track and display the real-time count of users currently active on your web application. With seamless integration, this package provides a quick and reliable solution for monitoring and presenting the dynamic online user presence, enhancing the overall user experience on your Laravel-powered website.

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

[](#installation)

You can install the package via composer:

```
composer require klevze/online-users
```

You can publish and run the migrations and configuration with:

```
php artisan vendor:publish --tag="online-users-migrations"
php artisan vendor:publish --tag="online-users-config"
php artisan migrate
```

Integration with Laravel's Kernel Middleware
--------------------------------------------

[](#integration-with-laravels-kernel-middleware)

To enable the "Online Users" middleware in your Laravel application, follow these steps:

1. Open the `app/Http/Kernel.php` file in your Laravel project.
2. Locate the `$middlewareGroups` property, specifically within the `web` middleware group.
3. Add the following line to the `web` middleware group:

    ```
    protected $middlewareGroups = [
        'web' => [
            // ... other middleware entries
            \Klevze\OnlineUsers\Middleware\TrackUserActivity::class,
            // ... other middleware entries
        ];
    ```

The "CleanupInactiveUsers" console command provided by the "Online Users" package allows you to remove inactive users from the `user_activities` table. Follow the steps below to integrate and schedule the cleanup task.

1. Open the `app/Console/Kernel.php` file in your Laravel project.
2. Locate the `schedule` method and add the following entry to schedule the `cleanup:inactive-users` command every five minutes:

    ```
    protected function schedule(Schedule $schedule)
    {
        // ... other scheduled tasks

        $schedule->command('cleanup:inactive-users')->everyFiveMinutes();

        // ... other scheduled tasks
    }
    ```
3. Save the changes to the `Kernel.php` file.

Now, the "CleanupInactiveUsers" console command will run every five minutes, cleaning up inactive users from the `user_activities` table.

Usage
-----

[](#usage)

Once package is installed, you can use the `OnlineUsers` class to get the number of active users. For example, the following code will get the number of active users:

```
$activeUsers = OnlineUsers::getActiveUsers();
```

Or you can use it directly in blade view:

```
Currently browsing: {{ OnlineUsers::getActiveUsers() ?? 0 }}

You can customize the activity threshold and tracking strategy by publishing and editing the `config/online-users.php` file.

Compatibility: This package supports Laravel 10, 11 and 12 and requires PHP 8.1 or newer. If you are using Laravel 12, ensure your application meets Laravel 12's PHP requirements.

### IP anonymization (privacy)

For privacy-conscious deployments you can anonymize user IP addresses before saving them to the database. To enable anonymization:

1. Publish the config: `php artisan vendor:publish --tag="online-users-config"`.
2. Set `anonymize_ip` to `true` and set `ip_salt` to a large secret string in `config/online-users.php` or via environment variables.

Or set in your `.env`:

```env
ONLINE_USERS_ANONYMIZE_IP=true
ONLINE_USERS_IP_SALT=your-long-random-salt
```

When enabled, the package will store a sha256 hash of the IP address concatenated with the salt to help protect user privacy while still allowing approximate uniqueness checks.

### Upgrading and migrating existing installs

[](#upgrading-and-migrating-existing-installs)

To add the `user_ip_hash` column (if you installed the package before hashed IP support was added) you should publish and run the new migration:

```
php artisan vendor:publish --tag="online-users-migrations"
php artisan migrate
```

After running the migration you can populate the newly created hash column using this command (requires a valid `ONLINE_USERS_IP_SALT`):

```
php artisan online-users:populate-ip-hash
```

The `online-users:populate-ip-hash` command will compute the hash for rows that don't yet have one. It uses your configured `ONLINE_USERS_IP_SALT` and `ONLINE_USERS_HASH_ALGORITHM`.

If you want to keep raw IPs along with hashed IPs for additional analysis, set `ONLINE_USERS_STORE_RAW_IP=true`.

### Dropping raw IPs (optional)

[](#dropping-raw-ips-optional)

If you decide to stop storing raw IPs after you are certain `user_ip_hash` has been populated, run the migration that removes the raw column:

```
php artisan vendor:publish --tag="online-users-migrations"
php artisan migrate
```

Before dropping raw IPs, please ensure you have a backup of your database. Recommended workflow:

1. Make a backup of your database.
2. Run `php artisan migrate` to add `user_ip_hash` (if not already present).
3. Run `php artisan online-users:populate-ip-hash` to fill the `user_ip_hash` column.
4. Verify data and application functionality.
5. If all good, run `php artisan migrate` which will pick up the `drop` migration to remove the `user_ip` column.

**Note:** hashing is irreversible; if you need the raw IP for logging, do not enable this option.

Demo
----

[](#demo)

You can see a working demo at these sites:

- [The Wallpapers](https://thewallpapers.net)
- [Joke Station](https://jokestation.org)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Automated Code Style Fixes
--------------------------

[](#automated-code-style-fixes)

This project runs `php-cs-fixer` in CI. To allow the code-style workflow to auto-commit fixes back to pull requests, add a repository secret named `STYLE_BOT_TOKEN` with a personal access token (PAT) that has `repo` permissions. When set, the workflow will commit fixes directly to the PR branch.

If you do not set `STYLE_BOT_TOKEN`, the workflow will attempt to use the default `GITHUB_TOKEN` where permitted (works for branches in the same repository but not for PRs from forks).

When the workflow runs on a PR it will now create a new pull request with automatic style fixes (rather than pushing changes directly to the originating branch). The original PR will receive a comment linking to the fixes PR.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance69

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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 ~225 days

Total

4

Last Release

182d ago

Major Versions

v0.1.2 → v1.2.02025-11-15

PHP version history (3 changes)v0.1PHP ^7.4

v0.1.1PHP &gt;=7.4

v1.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/efb51074ce79133d4a98dde8a328278388c6c899fa8303175b6a40239bf60b74?d=identicon)[klevze](/maintainers/klevze)

---

Top Contributors

[![klevze](https://avatars.githubusercontent.com/u/2184823?v=4)](https://github.com/klevze "klevze (34 commits)")

---

Tags

composercountlaravellaravel-middlewarelaravel-packagelaravel-packageslaravel12middlewareonlinepackagephpprivacyreal-timetrackinguser-activityuserslaravelUserscountonline

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/klevze-online-users/health.svg)

```
[![Health](https://phpackages.com/badges/klevze-online-users/health.svg)](https://phpackages.com/packages/klevze-online-users)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[highideas/laravel-users-online

This package will provide an online users management.

203113.2k1](/packages/highideas-laravel-users-online)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

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