Php “怎么做?”;“记住我”;laravel中的登录选项?

Php “怎么做?”;“记住我”;laravel中的登录选项?,php,authentication,laravel,laravel-4,Php,Authentication,Laravel,Laravel 4,因此,我正在处理的是,当我选中“记住我”复选框时,用户在注销表单时(用户名和密码)记住用户数据,如下所示: 这是我的代码,它不起作用:( 使用饼干 cookie是从网站发送的一小段数据,在用户浏览该网站时存储在用户的web浏览器中。每次用户加载该网站时,浏览器都会将cookie发送回服务器,以通知该网站用户以前的活动 要创建: $response->withCookie(Cookie::make('name', 'value', $minutes)); 取回 $value = Cooki

因此,我正在处理的是,当我选中“记住我”复选框时,用户在注销表单时(用户名和密码)记住用户数据,如下所示:

这是我的代码,它不起作用:(

使用饼干

cookie是从网站发送的一小段数据,在用户浏览该网站时存储在用户的web浏览器中。每次用户加载该网站时,浏览器都会将cookie发送回服务器,以通知该网站用户以前的活动

要创建:

$response->withCookie(Cookie::make('name', 'value', $minutes));
取回

$value = Cookie::get('name');
您的问题不是记住用户登录。问题是如何根据保存的身份验证信息填写输入。如果在加载页面时在“输入值”属性中打印身份验证值,则可以这样做。

此外,Laravel还有自己的“记住我”实现


有关

的详细信息您可以通过设置
Cookie
记住登录。Cookie将存储在浏览器存储器中。它是从网站发送的一小段数据,在用户浏览特定网站时存储在用户的web浏览器中。每次用户加载网站时,浏览器都会将Cookie发送回浏览器服务器通知网站用户以前的活动。在Laravel中,您可以将cookie设置为

$response->withCookie(Cookie::make('Cookie\u NAME','Cookie\u VALUE',$minutes');
//或
back()->->withCookie(Cookie::make('Cookie\u NAME','Cookie\u VALUE',$minutes))
如果您想从中间件设置cookie,以下是方法

公共函数句柄($request,Closure$next){
$response=$next($request);
$response->withCookie(Cookie::make('Cookie\u NAME','Cookie\u VALUE',$minutes))
}
您可以通过
lightize\Support\Facades\cookie
类创建/检索cookie,也可以使用laravel的全局
cookie()
helper函数

要检索cookie

$value=Cookie::get('Cookie_NAME');
//或
$request->cookie('cookie\u NAME')
请记住,默认情况下,Laravel加密cookie。中间件
EncryptCookie
负责加密cookie。检索此类cookie时,您将获得
null
。禁用/删除
EncryptCookie
中间件不是解决方案

您可以按如下方式对cookie进行加密:

protected$except=[
“COOKIE_NAME”,
];

使用Auth-您是否确保表用户具有标记的“记住我”列?
$value = Cookie::get('name');
if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
// The user is being remembered...
}

if (Auth::viaRemember())
{
//
}
public function validate() 
{
    // set the remember me cookie if the user check the box
    $remember = (Input::has('remember')) ? true : false;

    // attempt to do the login
    $auth = Auth::attempt(
        [
            'username'  => strtolower(Input::get('username')),
            'password'  => Input::get('password')    
        ], $remember
    );
    if ($ auth) {
        return Redirect::to('home');
    } else {
        // validation not successful, send back to form 
        return Redirect::to('/')
            ->with Input(Input::except('password'))
            ->with('flash_notice', 'Your username/password combination was incorrect.');
    }

}
$remember = true;
Auth::login($user, $remember);