{"id":15687413,"url":"https://github.com/wyrihaximus/reactphp-http-middleware-session","last_synced_at":"2025-05-07T08:29:52.894Z","repository":{"id":37514800,"uuid":"118382363","full_name":"WyriHaximus/reactphp-http-middleware-session","owner":"WyriHaximus","description":"Middleware that takes care of session handling","archived":false,"fork":false,"pushed_at":"2023-12-04T17:52:36.000Z","size":539,"stargazers_count":9,"open_issues_count":4,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-23T22:39:37.313Z","etag":null,"topics":["cookie","cookies","hacktoberfest","http","middleware","php","php7","reactphp","session"],"latest_commit_sha":null,"homepage":"","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/WyriHaximus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"WyriHaximus"}},"created_at":"2018-01-21T23:14:53.000Z","updated_at":"2022-02-12T10:52:57.000Z","dependencies_parsed_at":"2023-12-04T18:57:01.015Z","dependency_job_id":null,"html_url":"https://github.com/WyriHaximus/reactphp-http-middleware-session","commit_stats":{"total_commits":102,"total_committers":6,"mean_commits":17.0,"dds":"0.42156862745098034","last_synced_commit":"63c97f58dc7f79832bf7639431c6b40d77932e76"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WyriHaximus%2Freactphp-http-middleware-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WyriHaximus%2Freactphp-http-middleware-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WyriHaximus%2Freactphp-http-middleware-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WyriHaximus%2Freactphp-http-middleware-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WyriHaximus","download_url":"https://codeload.github.com/WyriHaximus/reactphp-http-middleware-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222688211,"owners_count":17023296,"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":["cookie","cookies","hacktoberfest","http","middleware","php","php7","reactphp","session"],"created_at":"2024-10-03T17:48:06.345Z","updated_at":"2024-11-02T08:06:32.028Z","avatar_url":"https://github.com/WyriHaximus.png","language":"PHP","funding_links":["https://github.com/sponsors/WyriHaximus"],"categories":[],"sub_categories":[],"readme":"# Middleware that takes care of session handling\n\n![Continuous Integration](https://github.com/wyrihaximus/php-http-middleware-session/workflows/Continuous%20Integration/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/wyrihaximus/http-middleware-session/v/stable.png)](https://packagist.org/packages/wyrihaximus/http-middleware-session)\n[![Total Downloads](https://poser.pugx.org/wyrihaximus/http-middleware-session/downloads.png)](https://packagist.org/packages/wyrihaximus/http-middleware-session/stats)\n[![Code Coverage](https://coveralls.io/repos/github/WyriHaximus/php-http-middleware-session/badge.svg?branchmaster)](https://coveralls.io/github/WyriHaximus/php-http-middleware-session?branch=master)\n[![Type Coverage](https://shepherd.dev/github/WyriHaximus/php-http-middleware-session/coverage.svg)](https://shepherd.dev/github/WyriHaximus/php-http-middleware-session)\n[![License](https://poser.pugx.org/wyrihaximus/http-middleware-session/license.png)](https://packagist.org/packages/wyrihaximus/http-middleware-session)\n\n# Install\n\nTo install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.\n\n```\ncomposer require wyrihaximus/react-http-middleware-session\n```\n\nThis middleware takes care of session handling. It uses [`react/cache`](https://reactphp.org/cache/) for storage or\nany cache handler implementing [`React\\Cache\\CacheInterface`](https://github.com/reactphp/react/wiki/Users#cache-implementations).\n\n# Usage\n\n```php\n$server = new Server(\n    $loop,\n    /** Other Middleware */\n    new SessionMiddleware(\n        'CookieName',\n        $cache, // Instance implementing React\\Cache\\CacheInterface\n        [ // Optional array with cookie settings, order matters\n            0, // expiresAt, int, default\n            '', // path, string, default\n            '', // domain, string, default\n            false, // secure, bool, default\n            false // httpOnly, bool, default\n        ],\n    ),\n    /** Other Middleware */\n    function (ServerRequestInterface $request) {\n        $session = $request-\u003egetAttribute(SessionMiddleware::ATTRIBUTE_NAME);\n\n        // Overwrite session contents, the details of changing specific keys is up to you\n        $session-\u003esetContents([\n            'foo' =\u003e 'bar',\n        ]);\n\n        // Get session contents\n        var_export($session-\u003egetContents()); // Prints something like: ['foo' = 'bar']\n\n        return new Response();\n    }\n);\n```\n\n# Response cache\n\nUsing this middleware together with [`wyrihaximus/react-http-middleware-response-cache`](https://github.com/WyriHaximus/reactphp-http-middleware-response-cache) then\nplease take a look at [`wyrihaximus/react-http-middleware-response-cache-session-cache-configuration`](https://github.com/WyriHaximus/reactphp-http-middleware-response-cache-session-cache-configuration) to\nensure you don't cache responses from users with active sessions.\n\n## To/From array\n\nIn case you need to pass a session into a child process it has `toArray` and `fromArray` methods:\n\n```php\n$array = $session-\u003etoArray();\n// Transfer to child process\n$session = (new Session('', [], new RandomBytes()))-\u003efromArray($array);\n// The same can be done transferring changes back to the parent\n```\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2020 Cees-Jan Kiewiet\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwyrihaximus%2Freactphp-http-middleware-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwyrihaximus%2Freactphp-http-middleware-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwyrihaximus%2Freactphp-http-middleware-session/lists"}