您现在的位置是:网站首页> 编程资料编程资料

解决laravel session失效的问题_php实例_

2023-05-25 267人已围观

简介 解决laravel session失效的问题_php实例_

最新在学习laravel,用到了session,因为laravel没法用$_SESSION 所以只能用框架的session。

贴上代码

$team_id]); Session::put('team_id',$team_id); Session::put('uuid',$uuid); Session::put('key',$key); Session::save(); } public static function islogin(){ $team_id=Session::get('team_id'); $uuid=Session::get('uuid'); $key=Session::get('key'); if(!empty($team_id)&&!empty($uuid)){ if($key != 1234){ echo "没有权限"; exit; } }else{ echo "没有权限"; exit; } } }

在当前页面可以到SESSION,但是跨页面就失效,以为是AJAX的CSRF验证问题,查找试了不是,然后经过打印发现2个SESSION不一致,继续检查最后发现是在定义路由的时候没有定义在同一个分组内所以导致SESSION不一致。

将路由重新定义好了

 Route::group(['middleware'=>'web'],function() { Route::any('/report/billviews', 'report\UserbillController@BillViews'); Route::any('/report/index','report\UseraccessController@index');//把需要用到session的路由请求全部放在web组里。 Route::any('/report/countprice', 'report\UserbillController@CountPrice'); Route::any('islogin', 'CommonController@islogin'); Route::any('login', 'CommonController@login'); });

还有个坑laravel5.2的session必须要过中间件

以上这篇解决laravel session失效的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

-六神源码网