Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:38:10+00:00 2026-05-31T16:38:10+00:00

For whatever reason, Sessions don’t work in my Silex-app. I set error_reporting in my

  • 0

For whatever reason, Sessions don’t work in my Silex-app. I set error_reporting in my php.ini to E_ALL | E_STRICT and errors are displayed and logged. Nothing to see there. But for some reason no session is created and there is no file in /project-root/tmp/sessions/ (and also not, when using the default session.save_path). Switching to PdoSessionStorage, to rule out problems with read/write-permissions on the filesystem, brought no results either. I also tried switching between $app['session'], $request->getSession() and $app['request']->getSession() to no avail.

I am at a loss as to where else to look for problems…

Here is a very simple test-app I wrote (use is omitted to save space). Basically this test shows what I try to achieve in my actual app. I want to store an array in the session. In $app->before() I check if the value is set and then pass it to twig to be displayed, e.g. login info: You are logged in as {{ user.name }}:

$app = new Application;
$app['debug'] = true;
$app->register(new SessionServiceProvider, array(
    'session.storage.save_path' => dirname(__DIR__) . '/tmp/sessions'
));
$app->register(new TwigServiceProvider, array(
    'twig.path' => __DIR__ . '/views'
));

$app->before(function (Request $request) use ($app) {
//    if ($app['debug'] == true) {
//        $request->getSession()->set('test', array('key' => 'value'));
//    }
    if ($request->hasPreviousSession() && $request->getSession()->has('test')) {
        $test = $request->getSession()->get('test');
        if ($test !== null) {
            $app['twig']->addGlobal('before', $test);
        }
    }
});

$app->get('/', function () use ($app) {
    return $app['twig']->render('sessiontest.twig');
});
$app->get('/test', function () use ($app) {
    $app['session']->set('test', array('key' => 'value'));
    return $app['twig']->render('sessiontest.twig',
        array('get' => $app['session']->get('test')));
});
$app->run();

sessiontest.twig looks like this:

<html>
<head><title>test</title></head>
<body>
    {% if before is defined %}before: {{ before.key }}{% endif %}
    {% if get is defined %}get: {{ get.key }}{% endif %}
</body>
</html>

When going to / nothing is displayed, when going to /test only “get: test” is displayed (but not actually stored, as neither returning to / nor refreshing triggers before).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:38:12+00:00Added an answer on May 31, 2026 at 4:38 pm

    Right now you need to start the session manually:

    $app->before(function ($request) {
        $request->getSession()->start();
    });
    

    There are tickets about this in the silex tracker, I haven’t had time to think about it yet. The problem is that if you do this, you will make a session for every user. Every using having a session, means every user gets cookies. Which is something you may not want. Which is the reason why it is not being started automatically at this point.

    I hope that clears things up a bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On whatever reason this is not working (says 'file not found'), set in=c:\myprogram\_save cd
For whatever reason, I need to go through a MySQL result set twice. Is
I'm using a honeycomb device to test my app and for whatever reason the
For whatever reason, std::cout does not display anything with my application. The description of
I have an ASP.NET web application that, for whatever reason, when it is deployed
I have a DateTime field in my form. For whatever reason, everytime I submit
I want to get this image uploading script right, but for whatever reason it
For whatever reason, I'm getting the error Invalid column name allocationStart when trying to
For whatever reason, my cucumber is using my _development db instead of my _test
I have a linq query that for whatever reason is not coming back ordered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.