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

danartinho's avatar

Setting session when login from remember me cookie

On my LoginController, when user successfully authenticated I set some cookies :

/**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        $request->session()->put('my_session_var', $my_session_value);
        // other things
        return false;
}

However, when I login with remember me checked, and then I reopen the page the next day, i cannot access the 'my_session_var' session.

My question is where can I set a session variable when user are authenticated using "remember me" cookie?

0 likes
1 reply
bobbybouwmann's avatar

Well you can't do that with sessions, because it's a session. You should either store that value in the database and retrieve it using the authenticated user id or store a cookie as well. The session will be gone when you close the browser or when you server restarts. However the cookie will remain active on the users browser.

Please or to participate in this conversation.