Php 尝试登录laravel时出现令牌问题
因此,我有一个登录功能张贴在下面,工作得很好,没有问题的大多数时间。但是,无论出于何种原因,如果您尝试登录主页,它都不会对您进行身份验证,并将url更改为以下内容Php 尝试登录laravel时出现令牌问题,php,authentication,laravel,laravel-4,token,Php,Authentication,Laravel,Laravel 4,Token,因此,我有一个登录功能张贴在下面,工作得很好,没有问题的大多数时间。但是,无论出于何种原因,如果您尝试登录主页,它都不会对您进行身份验证,并将url更改为以下内容 http://localhost/?_token=Jh36AX6sx0qhzOniPoMSn3pROCAVombCn4xKzoJm&email=admin%40admin.com&password=testpass 这对我来说毫无意义,它会抛出一些奇怪的错误,并以纯文本显示电子邮件和密码。有人知道发生了什么事吗?我在
http://localhost/?_token=Jh36AX6sx0qhzOniPoMSn3pROCAVombCn4xKzoJm&email=admin%40admin.com&password=testpass
这对我来说毫无意义,它会抛出一些奇怪的错误,并以纯文本显示电子邮件和密码。有人知道发生了什么事吗?我在任何其他页面上使用完全相同的功能,它工作得很好,但在主页上没有。我唯一一次看到url做类似的事情是在设置和重置密码的时候。有什么想法吗
public function doLogin()
{
// validate the info, create rules for the inputs
$rules = array(
'email1' => 'required|email', // make sure the email is an actual email
'password1' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails())
{
return Redirect::to('login')->withErrors($validator)->withInput(Input::except('password1')); // send back the input (not the password) so that we can repopulate the form
}
else
{
// create our user data for the authentication
$userdata = array(
'email' => Input::get('email1'),
'password' => Input::get('password1')
);
// attempt to do the login
if (Auth::attempt($userdata))
{
return Redirect::to('profile');
}
else
{
$this->layout->content = View::make('login')->with('p', 'Incorrect Login Information');
}
}
}
根据请求,这是调用函数的表单,它正在使用POST
{{ Form::open(array('url' => 'login', 'class' => 'form form-horizontal' ,'method' => 'post')) }}
{{ Form::text('email1', Input::old('email1'), array('class'=>'form-control','placeholder' => 'Email Address')) }}
{{ Form::password('password1', array('class'=>'form-control','placeholder' => 'Password')) }}
<button type="submit" class="btn btn-primary form-control">Login</button><br><br>
{{ HTML::link('login/fb', 'Sign-in with Facebook',array('class' => 'btn btn-primary form-control facebook')) }}
{{ HTML::link('password/remind', 'Forgot Password?') }}
{{ Form::close() }}
{{Form::open(数组('url'=>'login','class'=>'formform-Form-horizontal','method'=>'post'))}
{{Form::text('email1',Input::old('email1'),array('class'=>'Form-control','placeholder'=>'Email Address'))}
{{Form::password('password1',array('class'=>'Form-control','placeholder'=>'password'))}
登录
{{HTML::link('login/fb','Sign-in-with-Facebook',array('class'=>'btn-btn-primary-form-control-Facebook'))}
{{HTML::link('密码/提醒','忘记密码?')}
{{Form::close()}}
您的表单似乎使用了GET
而不是POST
。我建议发布您的表单代码以验证这一点。当您将其切换到POST
时,请确保您的路由已设置为将其作为POST
请求处理。这就是为什么我如此困惑的原因,我的应用程序中从未使用过get-anywhere。我可以在主编辑帖子中向您显示激活此表单的代码。最重要的是,登录的get只显示一个视图,所以这就更没有意义了,正确的表单是什么?我在你的URL中看到的是email1
和password1
而不是email
和password
。这是我的主要问题,我不知道URL是如何生成的,我什么都没做。我也尝试过将所有内容更改回电子邮件和密码,而不使用1,同样的问题发布您的路线?你肯定有点奇怪。甚至您的表单也应该提交到登录
url,但这似乎没有发生。顺便说一句,您所指的“奇怪错误”是什么?发现了问题,显然?\u token=是laravel通常在后端执行的操作,他们跟踪每个表单的标记显然发生了什么,我在这个页面上打开了一个,但没有关闭它。这导致它无法工作。如果将来有人遇到这种情况,请检查您的所有表单是否都已关闭。您能否显示用于显示登录
表单的控制器方法?