Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michalsn/codeigniter-session-extended
Manage database sessions in CodeIgniter 4
https://github.com/michalsn/codeigniter-session-extended
codeigniter codeigniter4 php php8 session session-management
Last synced: 4 months ago
JSON representation
Manage database sessions in CodeIgniter 4
- Host: GitHub
- URL: https://github.com/michalsn/codeigniter-session-extended
- Owner: michalsn
- License: mit
- Created: 2023-06-20T11:10:52.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2024-01-22T12:31:49.000Z (about 1 year ago)
- Last Synced: 2024-10-01T00:41:38.851Z (4 months ago)
- Topics: codeigniter, codeigniter4, php, php8, session, session-management
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CodeIgniter Session Extended
This library gives users the ability to view their own active sessions and remove them from devices they no longer use.
It works only with database session handler.
[![PHPUnit](https://github.com/michalsn/codeigniter-session-extended/actions/workflows/phpunit.yml/badge.svg)](https://github.com/michalsn/codeigniter-session-extended/actions/workflows/phpunit.yml)
[![PHPStan](https://github.com/michalsn/codeigniter-session-extended/actions/workflows/phpstan.yml/badge.svg)](https://github.com/michalsn/codeigniter-session-extended/actions/workflows/phpstan.yml)
[![Deptrac](https://github.com/michalsn/codeigniter-session-extended/actions/workflows/deptrac.yml/badge.svg)](https://github.com/michalsn/codeigniter-session-extended/actions/workflows/deptrac.yml)![PHP](https://img.shields.io/badge/PHP-%5E8.0-blue)
![CodeIgniter](https://img.shields.io/badge/CodeIgniter-%5E4.3-blue)### Requirements
This library requires the application to comply with CodeIgniter 4 [authentication recommendations](https://codeigniter.com/user_guide/extending/authentication.html).
### Installation
#### Composer
composer require michalsn/codeigniter-session-extended
#### Manually
In the example below we will assume, that files from this project will be located in `app/ThirdParty/session-extended` directory.
Download this project and then enable it by editing the `app/Config/Autoload.php` file and adding the `Michalsn\CodeIgniterSessionExtended` namespace to the `$psr4` array, like in the below example:
```php
APPPATH, // For custom app namespace
'Config' => APPPATH . 'Config',
'Michalsn\CodeIgniterSessionExtended' => APPPATH . 'ThirdParty/session-extended/src',
];// ...
```Now, follow the instructions of [configuring session database handler](https://codeigniter.com/user_guide/libraries/sessions.html#configure-databasehandler) - with one distinction. You have to use `Michalsn\SessionExtended\DatabaseHandler` class instead of the core one.
```php
list(user_id());return view('sessions/index', $data);
}public function delete()
{
if (! $this->request->is('post')) {
throw new PageNotFoundException();
}$rules = [
'id' => ['required', 'string', 'max_length[128]'],
];if (! $this->validate($rules)) {
return redirect()->back();
}$sm = new SessionManager();
if ($sm->delete($this->request->getPost('id'), user_id())) {
return redirect()->back()->with('success', 'Session was successfully deleted.');
}return redirect()->back()->with('error', 'Something went wrong.');
}
}
```