Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yigitozmen's avatar

session seems empty in another route

Hi, i am transporting data between pages via session. And i am sure that sessions are saved because i am dumping it and see on page where it saved. But i create test route for looking the session after every operation. But unfortunately i see empty session in test route..

0 likes
17 replies
bashy's avatar

Some type of code to see? Easier to reproduce then.

yigitozmen's avatar

alright,

   Route::get('/s-test', function (Request $request) {

return session()->all();
  });

this route returns empty session with only token and previous page (itself)

and this is from another page...

$request->session()->put('rsvInformation', $rsvInformation);
return $request->session()->all();

i see all rsvInformation in session here...

bashy's avatar

That works fine for me. Have you got any more of the code or how you've setup session/routes file? Are you using 5.2 with the "web" middleware?

yigitozmen's avatar

dear @bashy my script works well in my local server, but i am hosting this in digitalocean, i have this issue in digitalocean, maybe its about server... I don't know why this happens

d3xt3r's avatar

Load balancer ? Are you getting same session id on both routes ?

yigitozmen's avatar

@premsaurav i have checked laravel's storage folder, when i entered /x route it created new session file.... but why? i don't understand.

bashy's avatar

You could of said it's only happening on "production" :P Check the above (_token values) and then make sure you have the session setup correctly for the server. If you use something like 'secure' => true, then try access it via HTTP, it will reload the session on each load. Which is not what you want.

d3xt3r's avatar

can you share your routes file ? It shouldn't ? debug the request in chrome or browser of your choice ? see if session cookie is transmitted properly ?

yigitozmen's avatar

@premsaurav http://laravel.io/bin/QNx4y route file..

and this is cookie part and i see same in every page Cookie:XSRF-TOKEN=eyJpdiI6IlkwUVlEVW5OMDFGZnZGdzlTQU5ZOHc9PSIsInZhbHVlIjoiQWlpMTBzYk9GSDhvNWxWdWlLd0FGUXpCanVzaGs3QlJ2TG03WUNlb1hvTnVWUWtkNzFoTk1LVmdCNXVpdkx5T0c4cjZlTzJsOW5uZUtyM0dkbG9iQWc9PSIsIm1hYyI6IjM3YTllOTEyZjg3YmQ4Nzg1ODdhNGM1MTFiNmRiMzdiMjViOWJmYWU4ZWQ5MzNiYzQ2MGFhYjMyNWQ4M2NhNWYifQ%3D%3D; laravel_session=eyJpdiI6Im9tYnhLNUhzeURcLzlWRTJJdnE5WERBPT0iLCJ2YWx1ZSI6IkJUMlVNQjFZQWxXeHJEMzQ5S2lSWWNkZGdBMDBvUTREdjNVRWE5dEFrVTJRcXB6dnFneDc2S0p5TnlZQzVwSDVIcGRQb3d4bFRNYnYzZWxrSnAyaU93PT0iLCJtYWMiOiIyYjZiMWQzYzcxYzU0NjM5YWY5MDAzYzhhNDkwYzdjZjExMjQzMmE3YjA5ODBmMDIyMTVkMTRiOWZlZmEwMmNjIn0%3D

yigitozmen's avatar

@premsaurav i am using laravel 5.1 i think there is no web middleware? And this is the kernel.php

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel { /** * The application's global HTTP middleware stack. * * @var array */ protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, ];

/**
 * The application's route middleware.
 *
 * @var array
 */
protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
];

}

d3xt3r's avatar

@yigitozmen Yes, wont say bug (b'coz world would have been crying by now), may be some configuration issue. Put several dd() and try to figure out what. Things to check for ,am i getting proper cookies, what happening inside session middleware, when i save the data and my request returns is session data persisted in the files, so on and so forth ....

yigitozmen's avatar
yigitozmen
OP
Best Answer
Level 1

@premsaurav i found what is problem... www.domain.com and domain.com produce different sessions, so, i have redirected non-www to www and problem is solved.

1 like

Please or to participate in this conversation.