laravel登录后其他页面拿不到登录信息
登录本来是用表单的,我自作聪明的使用ajax提交
public function login(Request $request)
{ $data = $request->input();
$data = Deal::trim($data); $name = $data['name'];
$password = $data['password']; try{
if(empty($name)){
ExceptionResult::throwException(ErrorCode::USER_NOT_EMPTY);
} if(empty($password)){
ExceptionResult::throwException(ErrorCode::PASSWORD_NOT_EMPTY);
} $is_remeber = boolval(isset($data['is_remember']));
if(Auth::attempt(['name'=>$name,'password'=>$password],$is_remeber)) {
return redirect('/posts');
} else {
ExceptionResult::throwException(ErrorCode::LOGIN_FAILED);
} } catch (ExceptionResult $e){
return Redirect::back()->with('error', $e->getMessage())->withInput();
}
} 最开始我是直接返回json格式字符串,然后登录页面判断成功后直接跳转到首页
后来发现首页使用Auth::user()拿不到登录信息 查看了cookie session都没有值 想了想,如果用ajax 那么页面直接,登录成功后后台就没有设置session 后来改为使用表单就可了
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico"> <title>登陆</title> <!-- Bootstrap core CSS -->
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> <!-- Custom styles for this template -->
<link href="http://v3.bootcss.com/examples/signin/signin.css" rel="stylesheet"> <script src="/lib/jquery/jquery-2.2.1.js"></script>
<script src="/lib/layer/layer.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head> <body> <div class="container" id="app"> <form class="form-signin" method="POST" action="/login">
{{csrf_field()}}
<h2 class="form-signin-heading">请登录</h2>
<label for="inputName" class="sr-only">用户名</label>
<input v-model="form.name" autocomplete="off" type="text" value="{{ old("name") }}" name="name" id="inputName" class="form-control" placeholder="用户民" autofocus>
<label for="inputPassword" class="sr-only">密码</label>
<input v-model="form.password" autocomplete="off" type="password" value="{{ old('password') }}" name="password" id="inputPassword" class="form-control" placeholder="密码" >
<div class="checkbox">
<label>
<input v-model="form.is_remember" type="checkbox" value="{{ old('is_remember') }}" name="is_remember"> 记住我
</label>
</div> @if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
<button class="btn btn-lg btn-primary btn-block" type="submit" id="login">登陆</button>
<a href="/register" class="btn btn-lg btn-primary btn-block" type="submit">去注册>></a>
</form> </div> <!-- /container --> <script>
// var app = new Vue({
// el: '#app',
// data: {
// form:{
// name:'',
// password:'',
// _token:'',
// is_remember:0
// }
// },
// methods:{
// login:function(){
// this.form._token = $("#_token").val()
// axios.post('/login', this.form)
// .then(function (response) {
// var res = response.data;
// if(res.code != 200){
// layer.msg(res.msg,{icon:2});
// console.log(res.msg )
// return
// } else {
// layer.msg("登录成功",{icon:1});
// setTimeout("location.href='/posts'",2000);
// }
// })
// .catch(function (error) {
// console.log(error);
// });
// }
// }
// })
</script>
</body>
</html>
laravel登录后其他页面拿不到登录信息的更多相关文章
- Python爬虫教程-13-爬虫使用cookie爬取登录后的页面(人人网)(下)
Python爬虫教程-13-爬虫使用cookie爬取登录后的页面(下) 自动使用cookie的方法,告别手动拷贝cookie http模块包含一些关于cookie的模块,通过他们我们可以自动的使用co ...
- Python爬虫教程-12-爬虫使用cookie爬取登录后的页面(人人网)(上)
Python爬虫教程-12-爬虫使用cookie(上) 爬虫关于cookie和session,由于http协议无记忆性,比如说登录淘宝网站的浏览记录,下次打开是不能直接记忆下来的,后来就有了cooki ...
- 关于网站登录后的页面操作所携带的不同cookie值
对于课堂派网站,登录后的页面操作只需要携带PHPSESSID或者cookie中间那部分即可,两个都带也可,SERVERID不知道是干啥的,每次响应的都会变. 代码实现: cookie = None c ...
- python解析git log后生成页面显示git更新日志信息
使用git log可以查到git上项目的更新日志. 如下两个git项目,我想把git的日志信息解析成一个便于在浏览器上查看的页面. https://github.com/gityf/lua https ...
- yii2获取登录前的页面url地址--电脑和微信浏览器上的实现以及yii2相关源码的学习
对于一个有登录限制(权限限制)的网站,用户输入身份验证信息以后,验证成功后跳转到登录前的页面是一项很人性化的功能.那么获取登录前的页面地址就很关键,今天在做一个yii2项目的登录调试时发现了一些很有意 ...
- LR测试登陆后进行的操作时 绕过登录
oadrunner web_add_cookie web_add_cookie 这个的函数原来真的能过逃过登录,哈哈,这个苦苦纠结我的问题呀. 函数原型:int web_add_cookie( con ...
- Spring Security入门(2-3)Spring Security 的运行原理 4 - 自定义登录方法和页面
参考链接,多谢作者: http://blog.csdn.net/lee353086/article/details/52586916 http元素下的form-login元素是用来定义表单登录信息的. ...
- Laravel 登录后跳转回登录前浏览的页面
一.经过 Auth 中间件检查后跳转至登录页面 也就是没有通过 auth 中间件的认证检查,被 auth 中间件拦截后跳转至登录页面.这种情况下,Laravel 默认会在用户登录成功后自动跳转回登录前 ...
- Python手动构造Cookie模拟登录后获取网站页面内容
最近有个好友让我帮忙爬取个小说,这个小说是前三十章直接可读,后面章节需要充值VIP可见.所以就需要利用VIP账户登录后,构造Cookie,再用Python的获取每章节的url,得到内容后再使用 PyQ ...
随机推荐
- Docker容器(二)——镜像制作
制作Docker镜像有两种方式:第一种.docker commit,保存容器(Container)的当前状态到镜像后,然后生成对应的image:第二种.docker build,使用Dockerfil ...
- Swift4.0复习协议
1.协议的定义: /// 定义一个协议MyProt protocol MyProt { /// 声明了一个实例方法foo, /// 其类型为:() -> Void func foo() ...
- SET IDENTITY_INSERT的用法,具体去体验一下
如果将值插入到表的标识列中,需要启用 SET IDENTITY_INSERT. 举例如下: 创建表Orders.Products,Orders表与Products表分别有标识列OrderID与Prod ...
- 【Leetcode_easy】883. Projection Area of 3D Shapes
problem 883. Projection Area of 3D Shapes 参考 1. Leetcode_easy_883. Projection Area of 3D Shapes; 完
- echars 3.0 去掉柱状图阴影用什么属性
原图展示: 效果图展示: 在代码中注释掉这段 // tooltip : { // trigger: 'axis', // axisPointer : { // 坐标轴指示器,坐标轴触发有效 // ty ...
- Python3之内建模块collections
collections是python内建的一个集合模块,提供了许多有用的集合类. namedtuple 我们知道tuple可以表示不可变集合,例如,一个点的二维坐标可以表示成 >>> ...
- jcmd的简单实用
命令jcmd 显示所有java进程id及相关信息 命令 jcmd java_pid help 显示某个java进程的所有可用命令 ➜ jobs jcmd 61185 help 61185: The f ...
- IDEA将Git本地仓库Push至远程仓库
转自:https://blog.csdn.net/qq_15653601/article/details/79870996 本地本地仓库项目: 配置Git自动识别本机Git配置
- 问题(一)升级Appium最新遇到滑动的坑
Appium的JAVA客户端更新到java-client 6.0.0-BETA3后,发现其中有关于界面滑动(swipe TouchAction)方面的升级(也有可能在之前的版本已经更新过类似的内容,没 ...
- (模板)AC自动机模板
模板1. 给出模式串和文本串,文本串长度小于1e6,模式串长度之和小于1e6,求文本串中有多少模式串出现. 题目链接:https://www.luogu.org/problem/P3808 AC co ...