Some type of code to see? Easier to reproduce then.
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..
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...
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?

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
Load balancer ? Are you getting same session id on both routes ?
@premsaurav i have checked laravel's storage folder, when i entered /x route it created new session file.... but why? i don't understand.
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.
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 ?
@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 where's the web middleware ?
@premsaurav web middleware?
Sorry, are you using 5.1 or 5.2 :-)
@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,
];
}
Not able to replicate it ? Found similar problem, may be this could help https://laracasts.com/discuss/channels/general-discussion/laravel-5-creates-a-new-session-after-each-request :-/ Sorry
Could you also check, (taking a guess) if it works if you turn off the encryption
@premsaurav interesting thing is, my script works on local computer well. i'm not sure this is bug?
@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 ....
@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.
Please or to participate in this conversation.