{"id":13805669,"url":"https://github.com/bryanjhv/slim-session","last_synced_at":"2025-05-16T12:09:57.559Z","repository":{"id":34223490,"uuid":"38088623","full_name":"bryanjhv/slim-session","owner":"bryanjhv","description":"A very simple session middleware for Slim Framework 2/3/4.","archived":false,"fork":false,"pushed_at":"2024-01-17T13:40:50.000Z","size":58,"stargazers_count":232,"open_issues_count":0,"forks_count":40,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-02T05:44:48.028Z","etag":null,"topics":["middleware","php","session","slim-3"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/bryanjhv/slim-session","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bryanjhv.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-26T03:30:55.000Z","updated_at":"2025-03-31T06:35:49.000Z","dependencies_parsed_at":"2024-01-03T02:33:22.281Z","dependency_job_id":"a304d2db-943d-432a-a584-b6874f92489d","html_url":"https://github.com/bryanjhv/slim-session","commit_stats":{"total_commits":51,"total_committers":10,"mean_commits":5.1,"dds":0.2941176470588235,"last_synced_commit":"475accbe38622199fa1729f3caf5a38af2cda8a2"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryanjhv%2Fslim-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryanjhv%2Fslim-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryanjhv%2Fslim-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bryanjhv%2Fslim-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bryanjhv","download_url":"https://codeload.github.com/bryanjhv/slim-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994120,"owners_count":21030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["middleware","php","session","slim-3"],"created_at":"2024-08-04T01:01:03.636Z","updated_at":"2025-04-09T07:04:25.283Z","avatar_url":"https://github.com/bryanjhv.png","language":"PHP","readme":"# slim-session\n\nSimple middleware for [Slim Framework 4][slim], that allows managing PHP\nbuilt-in sessions and includes a `Helper` class to help you with the `$_SESSION`\nsuperglobal.\n\n**For the middleware version for Slim Framework 3, please check out the `slim-3`\nbranch in this repository.**\n\n**For the middleware version for Slim Framework 2, please check out the `slim-2`\nbranch in this repository.**\n\n## Installation\n\nAdd this line to `require` block in your `composer.json`:\n\n```json\n\"bryanjhv/slim-session\": \"~4.0\"\n```\n\nOr, run in a shell instead:\n\n```sh\ncomposer require bryanjhv/slim-session:~4.0\n```\n\n## Usage\n\n```php\n$app = \\Slim\\Factory\\AppFactory::create();\n$app-\u003eadd(\n  new \\Slim\\Middleware\\Session([\n    'name' =\u003e 'dummy_session',\n    'autorefresh' =\u003e true,\n    'lifetime' =\u003e '1 hour',\n  ])\n);\n```\n\n### Supported options\n\n- `lifetime`: How much should the session last? Default `20 minutes`. Any\n  argument that `strtotime` can parse is valid.\n- `path`, `domain`, `secure`, `httponly`, `samesite`: Options for the session\n  cookie. Please note that `samesite` is `'Lax'` by default, set to `''` to\n  disable.\n- `name`: Name for the session cookie. Defaults to `slim_session` (instead of\n  PHP's `PHPSESSID`).\n- **`autorefresh`**: `true` if you want session to be refresh when user activity\n  is made (interaction with server).\n- `handler`: Custom session handler class or object. Must implement\n  `SessionHandlerInterface` as required by PHP.\n- `ini_settings`: Associative array of custom [session configuration][sesscfg].\n  Previous versions of this package had some hardcoded values which could bring\n  serious performance leaks (see #30):\n  ```php\n  [\n    'session.gc_divisor' =\u003e 1,\n    'session.gc_probability' =\u003e 1,\n    'session.gc_maxlifetime' =\u003e 30 * 24 * 60 * 60,\n  ];\n  ```\n\n## Session helper\n\nA `Helper` class is available, which you can register globally or instantiate:\n\n```php\n$container = new \\DI\\Container();\n\n// Register globally to app\n$container-\u003eset('session', function () {\n  return new \\SlimSession\\Helper();\n});\n\\Slim\\Factory\\AppFactory::setContainer($container);\n```\n\nThat will provide `$app-\u003eget('session')`, so you can do:\n\n```php\n$app-\u003eget('/', function ($req, $res) {\n  // or $this-\u003eget('session') if registered\n  $session = new \\SlimSession\\Helper();\n\n  // Check if variable exists\n  $exists = $session-\u003eexists('my_key');\n  $exists = isset($session-\u003emy_key);\n  $exists = isset($session['my_key']);\n\n  // Get variable value\n  $my_value = $session-\u003eget('my_key', 'default');\n  $my_value = $session-\u003emy_key;\n  $my_value = $session['my_key'];\n\n  // Set variable value\n  $app-\u003eget('session')-\u003eset('my_key', 'my_value');\n  $session-\u003emy_key = 'my_value';\n  $session['my_key'] = 'my_value';\n\n  // Merge value recursively\n  $app-\u003eget('session')-\u003emerge('my_key', ['first' =\u003e 'value']);\n  $session-\u003emerge('my_key', ['second' =\u003e ['a' =\u003e 'A']]);\n  $letter_a = $session['my_key']['second']['a']; // \"A\"\n\n  // Delete variable\n  $session-\u003edelete('my_key');\n  unset($session-\u003emy_key);\n  unset($session['my_key']);\n\n  // Destroy session\n  $session::destroy();\n\n  // Get session id\n  $id = $this-\u003esession::id();\n\n  return $res;\n});\n```\n\n## Contributors\n\n[Here][contributors] are the big ones listed. :smile:\n\n## TODO\n\n- Complete `Helper` tests. (thanks @Zemistr)\n- Slim-specific tests (integration with Slim App).\n\n## License\n\nMIT\n\n[slim]: https://www.slimframework.com/docs/v4/\n[sesscfg]: https://www.php.net/manual/en/session.configuration.php\n[contributors]: https://github.com/bryanjhv/slim-session/graphs/contributors\n","funding_links":[],"categories":["Middlewares"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbryanjhv%2Fslim-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbryanjhv%2Fslim-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbryanjhv%2Fslim-session/lists"}