I'm new to the Slim framework. I'm trying to use the middleware functionality to do some authentication. However, Although I can set a cookie on one route, it disappears on a page refresh.
$app->get('/demo', function () use ($app) {
try {
$app->setCookie('uid', 'blah', '2 Days');
print_r($app);
} catch (Exception $e) {
$app->response()->status(400);
$app->response()->header('X-Status-Reason', $e->getMessage());
}
});
$app->run();
Doing the print_r shows that the cookie has been set
[cookies] => Slim\Http\Cookies Object ( [defaults:protected] => Array ( [value] => [domain] => [path] => [expires] => [secure] => [httponly] => ) [data:protected] => Array ( [uid] => Array ( [value] => blah [domain] => [path] => / [expires] => 2 Days [secure] => [httponly] => ) [key] => Array ( [value] => blah [domain] => [path] => / [expires] => 2 Days [secure] => [httponly] => ) ) ) [body:protected] => [length:protected] => 0 ) )
Or at least setCookie is picking up the value. However, if I then go to my other route
$app->get('/attractions', function () use ($app) {
try {
print_r($app);
$data = R::find('attractions');
$app->render('attractions.php', array(
'page_title' => "Attractions",
'data' => $data
)
);
} catch (Exception $e) {
$app->response()->status(400);
$app->response()->header('X-Status-Reason', $e->getMessage());
}
});
Then the cookies are not in there. Also in the logs of my firebug console there is no cookie showing up which I have set.
Any idea what the problem might be? I've found a couple of posts online like http://help.slimframework.com/discussions/problems/652-cant-seem-to-get-php-cookies-working
but I can't figure out the problem so far. I'm running MAMP and I've got a vhost set up for the domain.
Mcrypt php extension is enabled.
Any ideas?