Session is empty

after request sample/one and I’m hoping that sample/two get data from the session but the session data is empty
even session_start(); is declared please help me out or any suggestion

$app->post(’/sample/one’, function (Request $request, Response $response, $args) {

   $update = $request->getBody();
   return $response;


$app->post(’/sample/two’, function (Request $request, Response $response, $args) {

  $update = $request->getBody();
   return $response;


Welcome @edev5 :slight_smile:

Where do you invoke the session_start(); function?
Do you have a middleware for this purpose?

Make sure that $update->data is not empty. Try to set a fixed test value (e.g. “1”).

I put session_start(); at the top then I try $_SESSION[“data”]=“sample”; but still not work

@odan it possible to use session_start(); instead of Symfony Session

When you use Symfony Session then you have to invoke $session->start(); method. When you use the native PHP $_SESSION variable you have to call the session_start(); function for each request.

I tried Symfony Session and PhpSession it works but why session not work in subdomain?

This behavior also depends on the cookie settings and the browser.
In most cases, cookies are valid on a domain and all subdomains.

If the domain name in your cookie’s domain parameter doesn’t start with a period, then it will not let subdomains read that cookie. If it does start with the period, then all subdomains will have full access to that cookie’s value.

Generally it’s better to operate only in one domain when working with cookies (and ajax).