{"id":21467411,"url":"https://github.com/elusivecodes/fyresession","last_synced_at":"2025-07-15T05:31:30.393Z","repository":{"id":62508434,"uuid":"474308775","full_name":"elusivecodes/FyreSession","owner":"elusivecodes","description":"FyreSession is a free, open-source session library for PHP.","archived":false,"fork":false,"pushed_at":"2024-08-04T06:36:33.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-10T08:08:07.942Z","etag":null,"topics":["database","memcached","mysql","php","redis","session"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elusivecodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-03-26T10:06:02.000Z","updated_at":"2024-08-04T06:36:28.000Z","dependencies_parsed_at":"2024-08-04T07:52:46.888Z","dependency_job_id":null,"html_url":"https://github.com/elusivecodes/FyreSession","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreSession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreSession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreSession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreSession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreSession/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017472,"owners_count":17560519,"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":["database","memcached","mysql","php","redis","session"],"created_at":"2024-11-23T08:17:54.580Z","updated_at":"2025-07-15T05:31:30.378Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreSession\r\n\r\n**FyreSession** is a free, open-source session library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Session Handlers](#session-handlers)\r\n    - [Database](#database)\r\n        - [MySQL](#mysql)\r\n        - [Postgres](#postgres)\r\n    - [File](#file)\r\n    - [Memcached](#memcached)\r\n    - [Redis](#redis)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/session\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Session\\Session;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n```php\r\n$session = new Session($container, $config);\r\n```\r\n\r\nDefault configuration options will be resolved from the \"*Session*\" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `cookie` is an array containing session cookie options.\r\n        - `name` is a string representing the cookie name, and will default to \"*FyreSession*\".\r\n        - `expires` is a number representing the cookie lifetime, and will default to *0*.\r\n        - `domain` is a string representing the cookie domain, and will default to \"\".\r\n        - `path` is a string representing the cookie path, and will default to \"*/*\".\r\n        - `secure` is a boolean indicating whether to set a secure cookie, and will default to *true*.\r\n        - `sameSite` is a string representing the cookie same site, and will default to \"*Lax*\".\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `path` is a string representing the session path, and will default to \"*sessions*\".\r\n    - `handler`\r\n        - `className` must be set to `\\Fyre\\Session\\Handlers\\Database\\PostgresSessionHandler`.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session', $options);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *Session* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(Session::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$session = $container-\u003euse(Session::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Clear**\r\n\r\nClear the session data.\r\n\r\n```php\r\n$session-\u003eclear();\r\n```\r\n\r\n**Consume**\r\n\r\nRetrieve and delete a value from the session.\r\n\r\n- `$key` is a string representing the session key.\r\n\r\n```php\r\n$value = $session-\u003econsume($key);\r\n```\r\n\r\n**Delete**\r\n\r\nDelete a value from the session.\r\n\r\n- `$key` is a string representing the session key.\r\n\r\n```php\r\n$session-\u003edelete($key);\r\n```\r\n\r\n**Destroy**\r\n\r\nDestroy the session.\r\n\r\n```php\r\n$session-\u003edestroy();\r\n```\r\n\r\n**Get**\r\n\r\nRetrieve a value from the session.\r\n\r\n- `$key` is a string representing the session key.\r\n\r\n```php\r\n$value = $session-\u003eget($key);\r\n```\r\n\r\n**Has**\r\n\r\nDetermine whether a value exists in the session.\r\n\r\n- `$key` is a string representing the session key.\r\n\r\n```php\r\n$has = $session-\u003ehas($key);\r\n```\r\n\r\n**ID**\r\n\r\nGet the session ID.\r\n\r\n```php\r\n$id = $session-\u003eid();\r\n```\r\n\r\n**Is Active**\r\n\r\nDetermine whether the session is active.\r\n\r\n```php\r\n$isActive = $session-\u003eisActive();\r\n```\r\n\r\n**Refresh**\r\n\r\nRefresh the session ID.\r\n\r\n- `$deleteOldSession` is a boolean indicating whether to delete the old session, and will default to *false*.\r\n\r\n```php\r\n$session-\u003erefresh($deleteOldSession);\r\n```\r\n\r\n**Set**\r\n\r\nSet a session value.\r\n\r\n- `$key` is a string representing the session key.\r\n- `$value` is the value to set.\r\n\r\n```php\r\n$session-\u003eset($key, $value);\r\n```\r\n\r\n**Set Flash**\r\n\r\nSet a session flash value.\r\n\r\n- `$key` is a string representing the session key.\r\n- `$value` is the value to set.\r\n\r\n```php\r\n$session-\u003esetFlash($key, $value);\r\n```\r\n\r\n**Set Temp**\r\n\r\nSet a session temporary value.\r\n\r\n- `$key` is a string representing the session key.\r\n- `$value` is the value to set.\r\n- `$expire` is a number indicating the number of seconds the value will be valid, and will default to *300*.\r\n\r\n```php\r\n$session-\u003esetTemp($key, $value, $expire);\r\n```\r\n\r\n**Start**\r\n\r\nStart the session.\r\n\r\n- `$options` is an array containing configuration options.\r\n\r\n```php\r\n$session-\u003estart($options);\r\n```\r\n\r\n\r\n## Session Handlers\r\n\r\nYou can load a specific session handler by specifying the `Session.handler.className` [*Config*](https://github.com/elusivecodes/FyreConfig) option.\r\n\r\nCustom session handlers can be created by extending `\\Fyre\\Session\\SessionHandler` and implementing the [`SessionHandlerInterface`](https://www.php.net/manual/en/class.sessionhandlerinterface.php).\r\n\r\n\r\n### Database\r\n\r\nThe Database session handler can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Session\\Handlers\\DatabaseSessionHandler`.\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `prefix` is a string representing the session key prefix, and will default to \"\".\r\n    - `connectionKey` is a string representing the *Connection* key and will default to \"*default*\".\r\n    - `path` is a string representing the table name, and will default to \"*sessions*\".\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session.handler', $options);\r\n```\r\n\r\n#### MySQL\r\n\r\nThe MySQL database session handler can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Session\\Handlers\\Database\\MysqlSessionHandler`.\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `prefix` is a string representing the session key prefix, and will default to \"\".\r\n    - `connectionKey` is a string representing the *Connection* key and will default to \"*default*\".\r\n    - `path` is a string representing the table name, and will default to \"*sessions*\".\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session.handler', $options);\r\n```\r\n\r\n#### Postgres\r\n\r\nThe Postgres database session handler can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Session\\Handlers\\Database\\PostgresSessionHandler`.\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `prefix` is a string representing the session key prefix, and will default to \"\".\r\n    - `connectionKey` is a string representing the *Connection* key and will default to \"*default*\".\r\n    - `path` is a string representing the table name, and will default to \"*sessions*\".\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session.handler', $options);\r\n```\r\n\r\n### File\r\n\r\nThe File session handler can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Session\\Handlers\\FileSessionHandler`.\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `prefix` is a string representing the session key prefix, and will default to \"\".\r\n    - `path` is a string representing the directory path, and will default to \"*sessions*\".\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session.handler', $options);\r\n```\r\n\r\n### Memcached\r\n\r\nThe Memcached session handler can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Session\\Handlers\\MemcachedSessionHandler`.\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `prefix` is a string representing the session key prefix, and will default to \"*session:*\".\r\n    - `host` is a string representing the Memcached host, and will default to \"*127.0.0.1*\".\r\n    - `port` is a number indicating the Memcached port, and will default to *11211*.\r\n    - `weight` is a string representing the server weight, and will default to *1*.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session.handler', $options);\r\n```\r\n\r\n### Redis\r\n\r\nThe Redis session handler can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Session\\Handlers\\RedisSessionHandler`.\r\n    - `expires` is a number representing the maximum lifetime of a session, and will default to the `session.gc_maxlifetime` PHP setting.\r\n    - `prefix` is a string representing the session key prefix, and will default to \"*session:*\".\r\n    - `host` is a string representing the Redis host, and will default to \"*127.0.0.1*\".\r\n    - `password` is a string representing the Redis password\r\n    - `port` is a number indicating the Redis port, and will default to *6379*.\r\n    - `database` is a string representing the Redis database.\r\n    - `timeout` is a number indicating the connection timeout.\r\n    - `persist` is a boolean indicating whether to use a persistent connection, and will default to *true*.\r\n    - `tls` is a boolean indicating whether to use a tls connection, and will default to *true*.\r\n    - `ssl` is an array containing SSL options.\r\n        - `key` is a string representing the path to the key file.\r\n        - `cert` is a string representing the path to the certificate file.\r\n        - `ca` is a string representing the path to the certificate authority file.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Session.handler', $options);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyresession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyresession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyresession/lists"}