Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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 days ago
JSON representation

Manage database sessions in CodeIgniter 4

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.');
}
}
```