Welcome Guest, Not a member yet? Register   Sign In
session_destroy(): Trying to destroy uninitialized session
#1

(This post was last modified: 07-30-2023, 09:12 PM by kenjis.)

Hi this is my logout function:

Code:
122     public function logout()
123     {
124       session_destroy();
125
126       return redirect()->to('/admin/login');
127     }
128

The session is inizialized because in my template i print session()->get('admin_email') and i see it...
Reply
#2

What do you mean? What is your issue?

Even if you destroy the session, the session variables ($_SESSION) still exists in the request.

Also

Quote:You do not have to call this method from usual code. Cleanup session data rather than destroying the session.
https://codeigniter4.github.io/CodeIgnit...ml#destroy
Reply
#3

The error Is the tread's title. When i logout i have the errore.
Reply
#4

"Trying to destroy uninitialized session"
You tried to destroy uninitialized session, so you need to initialize the session before calling the session_destroy().
Reply
#5

(07-30-2023, 10:30 PM)kenjis Wrote: "Trying to destroy uninitialized session"
You tried to destroy uninitialized session, so you need to initialize the session before calling the session_destroy().

The session are inizialized , the admin is logged and i see the session()->get('admin_email') before click on logout
Reply
#6

When did you see the session()->get('admin_email') ?
If you saw it in the page before clicking the logout link,
yes, you actually initialized the session in the request.

But did you initialize the session in the request for logout?
If you really initialize the session, the error never occurs.
Or PHP goes crazy.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB