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

CyrilFour's avatar

Auth::login session ending right after [4.2]

Hi guys, i have an issue with the login function. I need to authenticate my users with a http header. It contains an id but no password so i'm using Auth::login() function. The user is logged in, but right after he's logged out. See my code here :

public function postLoginGassi() {
    try {
        $headers = apache_request_headers();
        $user = User::where('CUID', $headers['sm_universalid'])->first();
        //dd($headers);
        $var = Auth::loginUsingId($user['id']);
        Auth::login($var);
    } catch (Exception $ex) {
        return $headers;
    }
    if (Auth::check()) {
        switch (Auth::user()->role->name):
            case 'Pilote':
                return View::make('pilote.homePilote');
            case 'Opoci':
                return View::make('opoci.homeOpoci');
             case 'Soutient metier':
                 return View::make('SM.homeSM');
             case 'Responsable d\'equipe':
                 return View::make('re.homeRE');
        endswitch;
    } else {
        return "fail";
    }
}

Do you know why ?

Thanks,

0 likes
3 replies
CyrilFour's avatar

THank but i forgot to precise that i'm using laravel 4.2 due to the server's php version.

CyrilFour's avatar
CyrilFour
OP
Best Answer
Level 1

I found a solution, by setting the password of my users equal to their id(hashed), i can use the Auth::Attempt() method avoiding the session's problems.

public function postLoginGassi() { try { $headers = apache_request_headers(); if (Auth::attempt(['CUID' => $headers['sm_universalid'], 'password' => $headers['sm_universalid']])) { return Redirect::to('/'); } }

Please or to participate in this conversation.