php - Slim 3 post for every page with only one function -
i'm attempting add logout each 1 of pages when post
request sent. code working have define every route. there way can have $app->post()
on main routes file effect every page on site?
for example, on admin page have add code logout working:
$app->post('/admin', function ($request, $response) { // define post data $params = $request->getparams(); // logout user if ($params['logout']) { // logout user::logout(); // redirect login page return $response->withheader("location", "/"); } });
is there way can add single file , every other page such site.com/admin
, site.com/panel
able access this?
thanks
i solved using middleware.
// middleware logout $app->add(function ($request, $response, $next) { // define post data $params = $request->getparams(); // logout user if ($params['logout']) { // logout user::logout(); // redirect login page return $response->withheader("location", "/"); } // return next middleware return $next($request, $response); });
Comments
Post a Comment