Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alirezavalipour93's avatar

laravel 5.3 auth not working on session cookie base

hi i set my SESSION_DRIVER=file in .env file , user authtication work ok! but when i set SESSION_DRIVER=cookie my authentication not working all the time redirect me to login page here this is my code help me !!

public function userAuth($email = null, $mobile = null, $password)
{
    $user = new User();
    $user->setConnection('sqlite');
    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        $user = $user->where('email', $email)->first();
        session(['user' => $user]);
    //     dd(session());
        return true;
    } elseif (Auth::attempt(['mobile' => $mobile, 'password' => $password])) {
        $user = $user->where('mobile', $mobile)->first();
        session(['user' => $user]);
        dd(session('user'));
        return true;
    } else {
        return false;
    }
}

this my route:

Route::get('/', 'userController@test')->middleware('auth');
0 likes
3 replies
Waldemar's avatar

You use a session but not a cokie

session(['user' => $user]);

if use want use cokie, setup cokie and check cokie if cokie isset

$value = $request->cookie('name');
alirezavalipour93's avatar

i know that i use session , session has driver that sessions store in cookie so , here config/session that you can change session driver

berkayk's avatar

Have you found a solution for this? file setting for sessions was causing my server a performance trouble. With cookie setting, I cannot use authentication at all.

Please or to participate in this conversation.