When dealing with the problem of permission judgment, thinkphp5.1 middleware how to realize page redirection and display prompts.

problem description

assuming that the user is required to log in before publishing new information, determine whether the user is logged in or not and redirect the page by registering the middleware in the controller layer.

the environmental background of the problems and what methods you have tried

I intend to redefine the page by modifying the url within the request object, but this does not convey a prompt or redirect the page.

related codes

public function handle($request, \Closure $next)
    {
        dump(session("userInfo"));
        if (session("?userInfo")) {
            return $next($request);
        } else {
            $request->url = "/tp5/public/?s=/user/signIn";
            return $next($request);
        }
    }
Php
Feb.10,2022

The assignment method in the

problem code only assigns values to param ['url']. You can use the redirect helper function directly.

public function handle($request, \Closure $next)
    {
        if (session('?userInfo')) {
            return $next($request);
        } else {
            return redirect('/tp5/public/?s=/user/signIn',['message'=>'']);
        }
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32a82-341df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32a82-341df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?