Closed fredw closed 9 years ago
You must do $app->run()
in the end of your code. Following works for me.
require_once "../vendor/autoload.php";
$app = new \Slim\Slim();
$app->add(new \Slim\Middleware\SessionCookie());
$app->get("/foo", function() {
$_SESSION["test"] = "foo";
});
$app->get("/bar", function() {
var_dump($_SESSION);
});
$app->run();
When you add that middleware, you should no long use $_SESSION
. Instead, you may use encrypted cookies. From source code, you can see all functions about session are assigned to some functions that return boolean or empty string.
@fredw I am closing this one out, if you are still having trouble please open up a forum topic over at http://help.slimframework.com/ or come see us on irc channel #slimphp on freenode.
I am having trouble persisting session.
Am using HybridAuth library in a project that requires session_start
to work.
Including $app->add(new \Slim\Middleware\SessionCookie());
make things go awry but removing it return things back to normal.
Can someone please give a break down on how session can be persisted in different routes in slim framework?
Figured it out...
How did you solve it @collizo4sky ?
Since hybridAuth came with its own session handler, I had to use that instead of using that of slim.
I know this is old, but i was having a similar problem with sessions variables that were being "destroyed" when entering middlewares, refreshing the page or changing pages.
The only thing that worked for me was setting the session lifetime to higher than 0. For some reason my session maxlifetime was 0...
if (!isset($_SESSION)) session_start();
ini_set('session.cookie_lifetime', 3600);
ini_set('session.gc_maxlifetime', 3600);
session_set_cookie_params('3600');
setcookie(session_name(),session_id(),time()+3600);
Changing the urls in my html from "http://www" to "https://www" also helped...
I hope this is still open, i am having a serious issue using session wilt slim, my session is not accessible outside the route it was defined.
@saheedoladele i recently used this lib for a project https://github.com/bryanjhv/slim-session
Worked as expected
I'm using middleware
\Slim\Middleware\SessionCookie
to work with sessions, but the values are not persisting in different requests.I created a small test to simulate the problem:
File 1:
File 2:
First I make a request to File 1, after to File 2. The result is "null". I'm doing something wrong?