{"id":14977752,"url":"https://github.com/rancoud/session","last_synced_at":"2025-09-05T11:15:13.361Z","repository":{"id":37579856,"uuid":"121482873","full_name":"rancoud/Session","owner":"rancoud","description":"Session Package","archived":false,"fork":false,"pushed_at":"2025-01-31T20:26:16.000Z","size":577,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T12:06:50.224Z","etag":null,"topics":["composer","coverage","database","encryption","packagist","php","php74","php80","php81","phpunit","phpunit9","redis","session","sessionhandlerinterface"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/rancoud/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/rancoud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-14T07:27:23.000Z","updated_at":"2025-01-31T20:26:19.000Z","dependencies_parsed_at":"2024-01-04T11:32:14.978Z","dependency_job_id":"80343f69-4caa-4f2b-81c5-8810412057a0","html_url":"https://github.com/rancoud/Session","commit_stats":{"total_commits":249,"total_committers":3,"mean_commits":83.0,"dds":0.3293172690763052,"last_synced_commit":"58c896743f6db801ec3e08798d5353c6dd1e74d7"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FSession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FSession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FSession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FSession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rancoud","download_url":"https://codeload.github.com/rancoud/Session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238603665,"owners_count":19499488,"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":["composer","coverage","database","encryption","packagist","php","php74","php80","php81","phpunit","phpunit9","redis","session","sessionhandlerinterface"],"created_at":"2024-09-24T13:56:15.568Z","updated_at":"2025-02-13T05:35:09.687Z","avatar_url":"https://github.com/rancoud.png","language":"PHP","readme":"# Session Package\n\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/rancoud/session)\n[![Packagist Version](https://img.shields.io/packagist/v/rancoud/session)](https://packagist.org/packages/rancoud/session)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/rancoud/session)](https://packagist.org/packages/rancoud/session)\n[![Composer dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/rancoud/session/blob/master/composer.json)\n[![Test workflow](https://img.shields.io/github/actions/workflow/status/rancoud/session/test.yml?branch=master)](https://github.com/rancoud/session/actions/workflows/test.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/rancoud/session?logo=codecov)](https://codecov.io/gh/rancoud/session)\n\nSession.  \n\n## Installation\n```php\ncomposer require rancoud/session\n```\n\n## Informations\nBy default session is in read only (option read_and_close = 1).  \nYou can specify it using `Session::setReadWrite()` or `Session::setReadOnly()`  \n\nSession::start() is not needed, but: \n* Session will automatically start in read only when using `get, has, hasKeyAndValue, getAll`\n* Session will automatically start in write mode when using `set, remove, getAndRemove, keepFlash, gc, regenerate`\n\n## How to use it?\nSet and get value from $_SESSION\n```php\nSession::set('key', 'value');\n$value = Session::get('key');\n```\nUse custom options\n```php\n// first way\nSession::setOption('name', 'custom_session_name');\n\n// second way\nSession::start(['cookie_lifetime' =\u003e 1440]);\n\nSession::set('key', 'value');\n$value = Session::get('key');\n```\nWith encryption on default php session\n```php\nSession::useDefaultEncryptionDriver('keyForEncryption');\nSession::set('key', 'value');\n$value = Session::get('key');\n```\nWith File driver\n```php\nSession::useFileDriver();\nSession::set('key', 'value');\n$value = Session::get('key');\n```\nWith Database driver (you have to install rancoud/database)\n```php\n$conf = new \\Rancoud\\Database\\Configurator([\n    'engine'   =\u003e 'mysql',\n    'host'     =\u003e '127.0.0.1',\n    'user'     =\u003e 'root',\n    'password' =\u003e '',\n    'database' =\u003e 'test_database'\n]);\n$db = new \\Rancoud\\Database\\Database($conf);\n\n// for using a current connection\nSession::useCurrentDatabaseDriver($db);\n\n// for creating a new connection\n//Session::useNewDatabaseDriver($conf);\n\nSession::set('key', 'value');\n$value = Session::get('key');\n```\nWith Redis driver (you have to install predis/predis)\n```php\n$params = [\n    'scheme' =\u003e 'tcp',\n    'host'   =\u003e '127.0.0.1',\n    'port'   =\u003e 6379,\n];\n$redis = new Predis\\Client($params);\n\n// for using a current connection\nSession::useCurrentRedisDriver($redis);\n\n// for creating a new connection\n//Session::useNewRedisDriver($params);\n\nSession::set('key', 'value');\n$value = Session::get('key');\n```\nWith your own driver implementing `SessionHandlerInterface` and/or `SessionUpdateTimestampHandlerInterface`\n```php\n$driver = new MyCustomDriver();\nSession::useCustomDriver($driver);\nSession::set('key', 'value');\n$value = Session::get('key');\n```\n\n## Session\n### Static General Commands  \n* start([options: array = []]): void  \n* regenerate(): bool  \n* destroy(): bool  \n* commit(): void  \n* rollback(): bool  \n* unsaved(): bool  \n* hasStarted(): bool  \n* getId(): string  \n* setId(id: string): string  \n* gc(): void  \n* setReadOnly(): void  \n* setReadWrite(): void  \n* isReadOnly(): bool\n\n### Static Variables $_SESSION access\n* set(key: string, value: mixed): void  \n* get(key: string): mixed  \n* getAll(): array  \n* getAndRemove(key: string): mixed  \n* has(key: string): bool  \n* hasKeyAndValue(key: string, value: mixed): bool  \n* remove(key: string): void  \n\n### Static Variables flash access\nFlash data are store in a separate variable.  \nThey will dissapear at the end of the script execution or after `commit()` `unsaved()`.  \nYou can use keepFlash for saving it in $_SESSION.  \nWhen flash data is restore, it will be delete in $_SESSION.  \n\n* setFlash(key: string, value: mixed): void  \n* getFlash(key: string): mixed  \n* getAllFlash(): array  \n* hasFlash(key: string): bool  \n* hasFlashKeyAndValue(key: string, value: mixed): bool  \n* keepFlash([keys: array = []]): void  \n\n### Static Options  \n* setOption(key: string, value): void  \n* setOptions(options: array): void  \n* getOption(key: string): mixed  \n\n### Static Driver\n* getDriver(): \\SessionHandlerInterface  \n\n#### Static PHP Session Default Driver\n* useDefaultDriver(): void  \n* useDefaultEncryptionDriver(key: string, [method: string|null = null]): void  \n* setLengthSessionID(length: int): void  \n* getLengthSessionID(): int  \n\n#### Static File Driver\n* useFileDriver(): void  \n* useFileEncryptionDriver(key: string, [method: string|null = null]): void  \n* setPrefixForFile(prefix: string): void  \n* setLengthSessionID(length: int): void\n* getLengthSessionID(): int\n\n#### Static Database Driver\n* useNewDatabaseDriver(configuration: \\Rancoud\\Database\\Configurator|array): void  \n* useCurrentDatabaseDriver(databaseInstance: \\Rancoud\\Database\\Database): void  \n* useNewDatabaseEncryptionDriver(configuration: \\Rancoud\\Database\\Configurator|array, key: string, [method: string = null]): void  \n* useCurrentDatabaseEncryptionDriver(databaseInstance: \\Rancoud\\Database\\Database, key: string, [method: string = null]): void  \n* setUserIdForDatabase(userId: int): void  \n* setLengthSessionID(length: int): void\n* getLengthSessionID(): int\n\n#### Static Redis Driver\n* useNewRedisDriver(configuration: array|string): void  \n* useCurrentRedisDriver(redisInstance: \\Predis\\Client): void  \n* useNewRedisEncryptionDriver(configuration: array|string, key: string, [method: string = null]): void  \n* useCurrentRedisEncryptionDriver(redisInstance: \\Predis\\Client, key: string, [method: string = null]): void  \n* setLengthSessionID(length: int): void\n* getLengthSessionID(): int\n\n#### Static Custom Driver\n* useCustomDriver(customDriver: \\SessionHandlerInterface): void  \n\n## Session options\nList of session options you can change:  \n* save_path\n* name\n* save_handler\n* auto_start\n* gc_probability\n* gc_divisor\n* gc_maxlifetime\n* serialize_handler\n* cookie_lifetime\n* cookie_path\n* cookie_domain\n* cookie_secure\n* cookie_httponly\n* cookie_samesite\n* use_strict_mode\n* use_cookies\n* use_only_cookies\n* referer_check\n* cache_limiter\n* cache_expire\n* use_trans_sid\n* trans_sid_tags\n* trans_sid_hosts\n* sid_length\n* sid_bits_per_character\n* upload_progress.enabled\n* upload_progress.cleanup\n* upload_progress.prefix\n* upload_progress.name\n* upload_progress.freq\n* upload_progress.min_freq\n* lazy_write\n* read_and_close\n\n## Driver Informations\n### Default\nUse SessionHandler\n\n### File\nExtends SessionHandler\n\n### Database\nYou need to install\n```php\ncomposer require rancoud/database\n```\n\n```sql\nCREATE TABLE IF NOT EXISTS `sessions` (\n  `id` varchar(128) NOT NULL,\n  `id_user` int(10) unsigned DEFAULT NULL,\n  `last_access` datetime NOT NULL,\n  `content` text NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n```\n\n### Redis\nYou need to install\n```php\ncomposer require predis/predis\n```\n\n## How to Dev\n`docker compose build \u0026\u0026 docker compose run lib composer ci` for launching tests\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francoud%2Fsession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Francoud%2Fsession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francoud%2Fsession/lists"}