katalam/laravel-cookieless-session
Composer 安装命令:
composer require katalam/laravel-cookieless-session
包简介
This is my package laravel-cookieless-session
README 文档
README
Installation
You can install the package via composer:
composer require katalam/laravel-cookieless-session
You can publish the config file with:
php artisan vendor:publish --tag="cookieless-session-config"
This is the contents of the published config file:
return [ 'header' => [ 'name' => 'X-Session-Token', // The name of the header to be used 'include_with_response' => true, // Whether to include the session token in the response header ], 'parameter' => [ 'name' => '_session_token', // The name of the parameter to be used, either in the query string or in the request body ], ];
Usage
Inside bootstrap/app.php replace the StartSession middleware with the one provided by this package.
use Katalam\Cookieless\Http\Middleware\StartSession; use Illuminate\Session\Middleware\StartSession as DefaultStartSession; $middleware->web(replace: [ DefaultStartSession::class => StartSession::class, ]);
or use the middleware directly in your routes
use Katalam\Cookieless\Http\Middleware\StartSession; Route::get('/profile', function () { // ... })->middleware(StartSession::class);
Documentation
The package aims to provide a way to have a website without the ability to dispatch cookies and have a session at the same time. This is useful for websites that need to be GDPR-compliant and do not want to store any cookies on the user's device.
The technical implementation is based on the following principles:
We have a (new) Middleware named StartSession that is responsible for starting the session. We overwrite the default StartSession Middleware provided by Laravel at two points:
- We check the presence of cookies in the request and start the session normally if they are present.
- We also check the presence of a header or a parameter in the request. If they are present, we start the session with the (encrypted) session id provided in the header or parameter.
- We also do not send the session cookie in the response if the session was started with a header or parameter.
Now we need to understand two things:
- How is the session data stored?
- How is a user authenticated?
The session data is with various drivers stored in a persistent storage connected to the webserver. The session is identified by a unique string. We encrypt this string and send it to the client in some way. The client sends this string back to the server in the request. We decrypt this string and use it to identify the session. This is secure because the string is encrypted the same way as the session id in the cookie.
The user is authenticated by the session.
We pass the request inside the SessionGuard.php where
we check if the session has a user id inside the payload attribute.
To determine the key inside the payload for the user id, we have a combination of the word login,
the name of the auth guard and a hash of the absolute namespace from the auth guard.
This is to ensure that the key is unique for each auth guard.
What we essentially do is to replace the session cookie with a header or parameter. The rest of the internal handling of the session is the same as with the session cookie.
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
katalam/laravel-cookieless-session 适用场景与选型建议
katalam/laravel-cookieless-session 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Bruno Görß」 「laravel-cookieless-session」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 katalam/laravel-cookieless-session 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 katalam/laravel-cookieless-session 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 katalam/laravel-cookieless-session 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This bundle provides a simple command that will generate .bru files based on your registered routes using opctim/bruno-lang. Its usage is very similar to the commands of symfony/maker-bundle.
Framework-agnostic, bidirectional implementation of the Bruno (usebruno.com) .bru file language. Can be used to generate and parse from and to Bruno collections / request files.
Generate Bruno API collections from Laravel routes with automatic request body inference and environment support
Alfabank REST API integration
php artisan push - Deploy your codebase into your web server with a single Artisan command
Eduka backend
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-22