php - Start a session in read-only mode -
my problem following:
i have page runs series of ajax calls e.g.
$.ajax({ url: "/user/post1" }); $.ajax({ url: "/user/post2" }); $.ajax({ url: "/user/post3" }); ... $.ajax({ url: "/user/postn" });
(i've determined ids beforehand)
i've got:
$.ajax({ url: "/user/modifysessiondata" });
now problem need start session in each , every request (to current user) , in addition "/user/modifysessiondata" needs modify session data.
however i've noticed if execute ajax requests @ once it's possible if /user/postx
request starts before /user/modifysessiondata
request , ends after save session data when request called , therefore overwrite session data set 2nd call.
my question is:
is possible flag session started in specific request "read only"? need create new custom startsession
middleware this?
am doing ridiculous?
note: clarify i'm talking laravel session. using redis backed session storage.
in case helps ended doing:
in routeserviceprovider.php
boot()
method:
route::group([ 'middleware' => 'readonly', 'namespace' => $this->namespace, ], function ($router) { route::get("user/{post}","usercontroller@getpost"); });
in kernel.php
:
'readonly' => [ \app\http\middleware\encryptcookies::class, \illuminate\cookie\middleware\addqueuedcookiestoresponse::class, \app\http\middleware\startreadonlysession::class, \illuminate\view\middleware\shareerrorsfromsession::class, \app\http\middleware\verifycsrftoken::class, 'bindings', ]
this copied web
route group exception of startsession
swapped startreadonlysession
here's startreadonlysession
code (the punchline of issue):
use illuminate\session\middleware\startsession; class startreadonlysession extends startsession { public function terminate($request, $response) { /* nothing */ } }
this starts session not save when request terminates. else behaves identically.
Comments
Post a Comment