{"id":21771140,"url":"https://github.com/initphp/sessions","last_synced_at":"2026-04-12T21:39:30.775Z","repository":{"id":57714766,"uuid":"517560118","full_name":"InitPHP/Sessions","owner":"InitPHP","description":"InitPHP Sessions Manager","archived":false,"fork":false,"pushed_at":"2023-12-16T03:50:27.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T03:13:46.137Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/InitPHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-25T07:21:31.000Z","updated_at":"2022-07-25T07:24:02.000Z","dependencies_parsed_at":"2023-01-25T11:30:34.156Z","dependency_job_id":null,"html_url":"https://github.com/InitPHP/Sessions","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FSessions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FSessions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FSessions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FSessions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InitPHP","download_url":"https://codeload.github.com/InitPHP/Sessions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244746790,"owners_count":20503264,"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":[],"created_at":"2024-11-26T14:15:11.423Z","updated_at":"2026-04-12T21:39:30.687Z","avatar_url":"https://github.com/InitPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InitPHP Session Manager\r\n\r\n\r\n## Requirements\r\n\r\n- PHP 8.0 or later\r\n\r\n**Note :** Adapters used may have different dependencies.\r\n\r\n## Installation\r\n\r\n```\r\ncomposer require initphp/sessions\r\n```\r\n\r\n## Usage\r\n\r\n```php\r\nrequire_once \"vendor/autoload.php\";\r\nuse InitPHP\\Sessions\\Session;\r\n\r\nSession::createImmutable()\r\n    -\u003estart();\r\n    \r\n\r\nSession::set('username', 'admin')\r\n        -\u003eset('mail', 'admin@example.com');\r\n/**\r\n * OR\r\n * \r\n * $_SESSION['username'] = 'admin';\r\n * $_SESSION['mail'] = 'admin@example.com';\r\n */\r\n\r\necho Session::get('username', 'Undefined');\r\n/**\r\n * OR\r\n * \r\n * echo $_SESSION['username'] ?? 'Undefined';\r\n */\r\n```\r\n\r\n### Redis Adapter Usage\r\n\r\n```php\r\nrequire_once \"vendor/autoload.php\";\r\nuse InitPHP\\Sessions\\Session;\r\nuse InitPHP\\Sessions\\Adapters\\RedisAdapter;\r\n\r\n$adapter = new RedisAdapter([\r\n    'host'      =\u003e '127.0.0.1', // string\r\n    'port'      =\u003e 6379, // int\r\n    'timeout'   =\u003e 0, // int\r\n    'password'  =\u003e null, // null or string\r\n    'database'  =\u003e 0,\r\n    'ttl'       =\u003e 86400,\r\n    'prefix'    =\u003e 'sess'\r\n]);\r\n\r\nSession::createImmutable($adapter)\r\n    -\u003estart();\r\n```\r\n\r\n### PDO Adapter Usage\r\n\r\n```php\r\nrequire_once \"vendor/autoload.php\";\r\nuse InitPHP\\Sessions\\Session;\r\nuse InitPHP\\Sessions\\Adapters\\PDOAdapter;\r\n\r\n$pdo = new \\PDO('mysql:host=localhost;dbname=test', 'root', '');\r\n\r\n$adapter = new PDOAdapter(['pdo' =\u003e $pdo, 'table' =\u003e 'app_sessions']);\r\n\r\nSession::createImmutable($adapter)\r\n    -\u003estart();\r\n```\r\n\r\nExample MySQL Table Create SQL :\r\n\r\n```sql\r\nCREATE TABLE `sessions` (\r\n      `id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,\r\n      `sess_timestamp` timestamp NULL DEFAULT NULL,\r\n      `sess_ip_address` varchar(48) COLLATE utf8mb4_unicode_ci DEFAULT NULL\r\n      `sess_data` text COLLATE utf8mb4_unicode_ci NOT NULL,\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;\r\nALTER TABLE `sessions` ADD PRIMARY KEY (`id`);\r\n```\r\n\r\n\r\n### Memcache Adapter Usage\r\n\r\n```php\r\nrequire_once \"vendor/autoload.php\";\r\nuse InitPHP\\Sessions\\Session;\r\nuse InitPHP\\Sessions\\Adapters\\MemCacheAdapter;\r\n\r\n$adapter = new MemCacheAdapter([\r\n        'host'          =\u003e '127.0.0.1', // string\r\n        'port'          =\u003e 11211, // int\r\n        'weight'        =\u003e 1, // int\r\n        'raw'           =\u003e false, // boolean\r\n        'prefix'        =\u003e null, // null or string\r\n        'ttl'           =\u003e 86400, // int\r\n]);\r\n\r\nSession::createImmutable($adapter)\r\n    -\u003estart();\r\n```\r\n\r\n### Cookie Adapter Usage\r\n\r\n```php\r\nrequire_once \"vendor/autoload.php\";\r\nuse InitPHP\\Sessions\\Session;\r\nuse InitPHP\\Sessions\\Adapters\\CookieAdapter;\r\n\r\n$adapter = new CookieAdapter(['name' =\u003e 'sessDataCookieName', 'key' =\u003e 'topSecretAppKey', 'ttl' =\u003e 86400]);\r\n\r\nSession::createImmutable($adapter)\r\n    -\u003estart();\r\n```\r\n\r\n### MongoDB Adapter Usage\r\n\r\n```php\r\nrequire_once \"vendor/autoload.php\";\r\nuse InitPHP\\Sessions\\Session;\r\nuse InitPHP\\Sessions\\Adapters\\MongoDBAdapter;\r\n\r\n$adapter = new MongoDBAdapter(['dsn' =\u003e 'mongodb://127.0.0.1:27017', 'collation' =\u003e 'sessDbName.sessCollectionName']);\r\n\r\nSession::createImmutable($adapter)\r\n    -\u003estart();\r\n```\r\n\r\n## Credits\r\n\r\n- [Muhammet ŞAFAK](https://github.com/muhammetsafak) \u003c\u003cinfo@muhammetsafak.com.tr\u003e\u003e\r\n\r\n## License\r\n\r\nCopyright \u0026copy; 2022 [MIT License](./LICENSE)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Fsessions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finitphp%2Fsessions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Fsessions/lists"}