简体   繁体   English

我在Slim PHP框架中的会话在哪里?

[英]Where are my sessions in Slim PHP framework?

I'm using version 1.5.0 of the Slim PHP framework, and I'm having problems with sessions. 我正在使用Slim PHP框架的1.5.0版本,我遇到了会话问题。 I've had no problems in the past (using Slim), so it leads me to believe it's either something changing with Slim, or something with my setup. 我过去没有遇到过任何问题(使用Slim),所以它让我相信它是Slim的变化,或者是我的设置。 Here is a basic snippet of routes in my index.php page. 这是我的index.php页面中的基本路由片段。

$app->get('/test', function() use($app) {
    $_SESSION['test'] = 'blah';
    var_dump($_SESSION);
});

$app->get('/test2', function() use ($app) {
    var_dump($_SESSION);
});

The '/test' route outputs: '/ test'路线输出:

array(1) { ["test"]=> string(4) "blah" }

The '/test2' route outputs: '/ test2'路由输出:

array(0) { }

What is up with my sessions. 我的课程怎么样? Am I doing something wrong? 难道我做错了什么? Should I be using something else than PHP's native sessions? 我应该使用除PHP本地会话之外的其他内容吗? I've even tried initializing Slim with the following property: 我甚至尝试使用以下属性初始化Slim:

$app = new Slim(array(
    'session.handler' => null
));

Both options, to no avail. 两种选择都无济于事。

Slim has relied on encrypted HTTP cookies to persist session data; Slim依靠加密的HTTP cookie来保存会话数据; if you do not have cookies, you won't have sessions unless you set the session handler to null as you have done above. 如果您没有cookie,除非您将会话处理程序设置为null ,否则您将无法进行会话。

Version 1.6.0 (currently in the develop branch) does not make any assumptions about sessions; 版本1.6.0(目前在开发分支中)不对会话做出任何假设; instead, version 1.6.0 requires that you configure and start your own session (if using PHP's native session handling). 相反,版本1.6.0要求您配置和启动自己的会话(如果使用PHP的本机会话处理)。 Version 1.6.0 also abstracts the legacy session handling into middleware so that you can continue using encrypted cookies to persist session data if that's what you prefer. 版本1.6.0还将遗留会话处理抽象为中间件,以便您可以继续使用加密的cookie来保存会话数据,如果这是您喜欢的。

If you have any further questions, I encourage you to post them to the official Slim Framework support forum at http://help.slimframework.com/ . 如果您有任何其他问题,我建议您将它们发布到http://help.slimframework.com/上的官方Slim Framework支持论坛。

Best, Josh 最好的,约什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM