{"action":"created","issue":{"url":"https://api.github.com/repos/silexphp/Silex/issues/746","labels_url":"https://api.github.com/repos/silexphp/Silex/issues/746/labels{/name}","comments_url":"https://api.github.com/repos/silexphp/Silex/issues/746/comments","events_url":"https://api.github.com/repos/silexphp/Silex/issues/746/events","html_url":"https://github.com/silexphp/Silex/issues/746","id":16375581,"number":746,"title":"Session invalidate does not work (session not started automatically)","user":{"login":"peschee","id":63866,"avatar_url":"https://avatars.githubusercontent.com/u/63866?v=3","gravatar_id":"","url":"https://api.github.com/users/peschee","html_url":"https://github.com/peschee","followers_url":"https://api.github.com/users/peschee/followers","following_url":"https://api.github.com/users/peschee/following{/other_user}","gists_url":"https://api.github.com/users/peschee/gists{/gist_id}","starred_url":"https://api.github.com/users/peschee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peschee/subscriptions","organizations_url":"https://api.github.com/users/peschee/orgs","repos_url":"https://api.github.com/users/peschee/repos","events_url":"https://api.github.com/users/peschee/events{/privacy}","received_events_url":"https://api.github.com/users/peschee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2013-07-04T16:57:19Z","updated_at":"2015-08-03T14:25:16Z","closed_at":"2015-08-03T14:25:16Z","body":"Hi\r\n\r\nI recently discovered what seems to be a bug in the latest silex version. It seems that sessions cannot be invalidated with ```$app['session']->invalidate()``` without an explicit ```$app['session']->start()``` in e.g. the ```before``` middleware.\r\n\r\nIt seems that sessions should be started automatically upon initial access (#274). I've created a quick sample app to demonstrate the problem ([https://github.com/peschee/silex-session-bug](https://github.com/peschee/silex-session-bug)) which has the following structure:\r\n\r\n```php\r\n<?php\r\n\r\nrequire __DIR__ . '/../vendor/autoload.php';\r\n\r\nuse Silex\\Application;\r\nuse Silex\\Provider\\SessionServiceProvider;\r\nuse Symfony\\Component\\HttpFoundation\\Request;\r\nuse Symfony\\Component\\HttpFoundation\\Response;\r\n\r\ndefine('SESSION_KEY', 'some_key');\r\n\r\n$app = new Application();\r\n\r\n$app->register(new SessionServiceProvider());\r\n\r\n$app->before(function (Request $request) use ($app) {\r\n//    $app['session']->start();\r\n});\r\n\r\n$app->get('/', function () use ($app) {\r\n    return sprintf('Main<br /><br />Session: %s', $app['session']->get(SESSION_KEY));\r\n});\r\n\r\n$app->get('/set', function () use ($app) {\r\n    $app['session']->set(SESSION_KEY, 'some_value');\r\n\r\n    return sprintf('Set<br /><br />Session: %s', $app['session']->get(SESSION_KEY));\r\n});\r\n\r\n$app->get('/invalidate', function () use ($app) {\r\n    $app['session']->invalidate();\r\n\r\n    return sprintf('Set<br /><br />Session: %s', $app['session']->get(SESSION_KEY));\r\n});\r\n\r\n$app->run();\r\n```\r\n\r\nThe ```/set``` route correctly sets the session value. However, if I visis ```/``` after having invalidated the session in ```/invalidate```, the stored session value is still there. Adding ```$app['session']->start()``` in the before middleware solves the problem.\r\n\r\nIs this expected behavior? If so, we need to change the docs accordingly."},"comment":{"url":"https://api.github.com/repos/silexphp/Silex/issues/comments/127260138","html_url":"https://github.com/silexphp/Silex/issues/746#issuecomment-127260138","issue_url":"https://api.github.com/repos/silexphp/Silex/issues/746","id":127260138,"user":{"login":"fabpot","id":47313,"avatar_url":"https://avatars.githubusercontent.com/u/47313?v=3","gravatar_id":"","url":"https://api.github.com/users/fabpot","html_url":"https://github.com/fabpot","followers_url":"https://api.github.com/users/fabpot/followers","following_url":"https://api.github.com/users/fabpot/following{/other_user}","gists_url":"https://api.github.com/users/fabpot/gists{/gist_id}","starred_url":"https://api.github.com/users/fabpot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabpot/subscriptions","organizations_url":"https://api.github.com/users/fabpot/orgs","repos_url":"https://api.github.com/users/fabpot/repos","events_url":"https://api.github.com/users/fabpot/events{/privacy}","received_events_url":"https://api.github.com/users/fabpot/received_events","type":"User","site_admin":false},"created_at":"2015-08-03T14:25:16Z","updated_at":"2015-08-03T14:25:16Z","body":"Closing as there is a ticket on symfony/symfony about this problem."}}