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

drake24's avatar

SESSION GONE AFTER MULTIPLE REFRESHES

Hi,

As the title said, I have a problem with my Session variables, I already stored the details during log-in. However, after a couple of refreshes or navigation on the site I lose all of my Session variables.

Session.php

    'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 999,
'expire_on_close' => false,

and my Authenticate controller.

public function authenticate(){
    $username = Input::get('username');
    $password = Input::get('password');
    if (Auth::attempt(['username' => $username, 'password' => $password])) {
        // Authentication passed...
        // Store user data
        $this->storeSessionData();
        return redirect('dashboard');   
    }
    else{
        return 
            redirect()->back()->with('message', array('username' => $username));
    }
}

public function storeSessionData(){
    // Retrieves the authenticated user
    $user = Auth::user();
    // Set details to session.
    Session::put('firstname', $user->first_name);
    Session::put('lastname',  $user->last_name);
    Session::put('usertype',  $user->user_type); 
    Session::put('image',     $user->image);
    Session::put('mac',       ServerAddress::MACADDRESS());
}


public function logout(){
    //Logs user out
    Auth::logout();

    //Clears history
    Session::flush();

    //redirect back to login
    return redirect('login');
}
0 likes
0 replies

Please or to participate in this conversation.