Could you please help me, My code is not saving SESSION between requests.
when i Login, it always returns null in session.
Thank you in advance.
$app->get('/session', function($request, $response, $args) {
$session = new \SlimSession\Helper;
$reponse["uid"] = $session->uid;
$reponse["email"] = $session->email;
$reponse["name"] = $session->name;
echo json_encode($reponse);
});
$app->post('/connexion', function ($request, $response, $args) {
$reponse['status'] = "success";
$reponse['message'] = 'Vous êtes connecté.';
$reponse['name'] = "wassim boukadida";
$reponse['uid'] = "123456";
$reponse['email'] = "test@test.com";
$reponse['createdAt'] = "date_exmple";
//session saving
$session = new \SlimSession\Helper;
$session->uid = "123456";
$session->email = "test@test.com";
$session->name = "wassim boukadida";
echo json_encode($reponse);
});
You need to start the session, bryanjhv/slim-session
has already middleware for that, which you just need to add:
$app = new \Slim\App;
// add the middleware
$app->add(new \Slim\Middleware\Session());
// add routes
$app->run();
For settings look at the readme file of bryanjhv/slim-session
as this helper is currently in development
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.