https://github.com/anubra266/browser-sessions
🧑💻 Manage Browser Sessions in a Laravel Application
https://github.com/anubra266/browser-sessions
laravel php security session-management
Last synced: over 1 year ago
JSON representation
🧑💻 Manage Browser Sessions in a Laravel Application
- Host: GitHub
- URL: https://github.com/anubra266/browser-sessions
- Owner: anubra266
- License: mit
- Created: 2020-12-22T02:29:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-09-07T09:19:58.000Z (almost 3 years ago)
- Last Synced: 2025-02-26T20:22:18.600Z (over 1 year ago)
- Topics: laravel, php, security, session-management
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Browser Sessions
[](https://github.com/anubra266/browser-sessions/actions?query=workflow%3ATests)
[](https://packagist.org/packages/anubra266/browser-sessions)
[](https://github.com/anubra266/browser-sessions/blob/master/LICENSE)
[](https://packagist.org/packages/anubra266/browser-sessions)
[](https://github.com/anubra266)
Manage User Accounts' Browser Sessions in a Laravel Application.
## Contents
- [Features](#Features)
- [Installation](#installation)
- [Usage](#Usage)
- [Get Sessions](#Get-Sessions)
- [Backend](#Backend)
- [Output Format](#Output-Format)
- [Logout All Sessions](#Logout-All-Sessions)
- [Testing](#Testing)
- [Credits](#Credits)
- [License](#License)
## Features
- [x] List Browser Sessions
- [x] Logout All Browser Sessions
## Installation
You can install the package via composer:
```bash
composer require anubra266/browser-sessions
```
Edit `config/session.php` and change the Driver
```php
'driver' => 'database'
```
Create Session Migration and Migrate
```bash
php artisan session:table
php artisan migrate
```
Make sure that the `Illuminate\Session\Middleware\AuthenticateSession` middleware is present and un-commented in your `app/Http/Kernel.php class` web middleware group:
```php
'web' => [
// ...
\Illuminate\Session\Middleware\AuthenticateSession::class,
// ...
],
```
You can publish the config file with:
```bash
php artisan vendor:publish --provider="Anubra266\BrowserSessions\BrowserSessionsServiceProvider" --tag="config"
```
## Usage
### Get Sessions
#### **Backend**
```php
# SettingsController.php
//Get a collection of sessions
public function showSessions(){
// This method accepts the request instance
$sessions = BrowserSessions::collect(request());
//Pass the collection to your view
return view('sessions', ["sessions" => $sessions->all()]);
}
```
#### **Output Format**
```js
{
'agent' :{
'is_desktop' : boolean,
'platform' : string,
'browser' : string,
},
'ip_address' : string,
'is_current_device' : boolean,
'last_active' : string,
}
```
## Logout All Sessions
Send a Post Request to the named route `browser.sessions.logout`.
```html
@csrf
Logout All Devices
```
**NB**:
- You can change this named route by changing the value of the `logoutAllSessions` key in `config/browser-sessions.php`.
- Validation errors are returned in errorBag named `logoutOtherBrowserSessions`. You can change this by editing the value of the `errorBag` key in `config/browser-sessions.php`.
## Testing
```bash
composer test
```
## Credits
- [Abraham](https://github.com/Abraham)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.