lavarel5.2中非法登录

第一步:打开routes.PHP文件,把登录进去之后的所有方法放到Route::group(['middleware' => 'auth'], function () {放在此处 });里

例:

      //首页
        Route::any('/', 'LoginController@login');
        Route::any('login', 'LoginController@login');//登录页面
        Route::any('address', 'LoginController@address');//第三方登录的回调的方法(地址)
        Route::group(['middleware' => 'auth'], function () {//非法登录开始
        Route::any('index', 'IndexController@index');//登录成功之后所去的方法
        Route::any('summan', 'IndexController@summan');
        Route::any('tiyu', 'IndexController@tiyu');
        Route::any('xin', 'IndexController@xin');
        Route::any('study', 'IndexController@study');
        Route::any('city','IndexController@city');
        Route::any('comecity','IndexController@comecity');
        Route::any('sou','IndexController@sou');
        Route::any('search','IndexController@search');
        //播放页
        Route::any('money', 'MovieController@money');
        Route::any('recharge', 'MovieController@recharge');
        Route::any('pay', 'MovieController@pay');
        Route::any('pay_db', 'MovieController@pay_db');
        Route::any('pay_user', 'MovieController@pay_user');
        Route::any('fanhui', 'MovieController@fanhui');
        Route::any('hot', 'MovieController@hot');
        Route::any('movie', 'MovieController@movie');
        //用户中心
        Route::any('user', 'UserController@user');
        Route::any('guanzu', 'UserController@guanzu');
        Route::any('user_center','UserController@user_center');
        Route::any('lahei','UserController@lahei');
        Route::any('loginout', 'LoginController@Loginout');

    });//非法登录结束

第二步:在app->Http->Middleware里新建PowerLogin.php文件

内容为:

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Redirect;
use Session;


class PowerLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        session_start();//开启session
        //echo $_SESSION['username'];die;
        if(!empty($_SESSION['username'])){//判断是否有session值username
            //echo "有session值";
            return $next($request);
        }
        else{
            //return Redirect('login');
            echo "<script>alert('请先去登录');location.href='login'</script>";
        }


    }
}

第三步:在app->Http->Kernel.php里面的最后一个方法加入一行:'auth' => \App\Http\Middleware\PowerLogin::class,//新加的

 如图:

 protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
         'auth' => \App\Http\Middleware\PowerLogin::class,//新加的,PowerLogin为第二步新建的类名.auth为第一步在routes.php文件里Route::group(['middleware' => 'auth'], function () {//非法登录开始的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值