Welcome Guest, Not a member yet? Register   Sign In
$session->destroy() throws exception
#1

(This post was last modified: 04-11-2024, 01:45 AM by joho.)

Why does this throw an exception?

PHP Code:
        $session = \Config\Services::session();
        $session_username $session->get'session_username' );
        $session_login_time $session->get'session_login_time' );
        $session_login_ip $session->get'session_login_ip' );
        if ( ! empty( $session_username) && ! empty( $session_login_time )  && ! empty( $session_login_ip ) ) {
            error_logbasename__FILE__ ) . ' (' __FUNCTION__ '): Session already active, re-directing to /' );
            return( $this->response->redirectbase_url() ) );
        }
        $ip_address $this->request->getIPAddress();
        if ( empty( $ip_address ) ) {
            error_logbasename__FILE__ ) . ' (' __FUNCTION__ '): Missing or invalid IP address "' $ip_address '", re-directing' );
            $session->destroy();
            return( $this->response->redirectbase_url() ) );
        }
        // .. code continues 

It throws an exception ("session_destroy(): Trying to destroy uninitialized session") when it gets to $session->destroy().

But if it's an uninitialized session, why doesn't it throw the exception sooner?

I honestly don't think the destroy() call should throw an exception. I have several blocks of code that do cleanup and then re-direct, so I add a destroy() call inside each of those blocks. I can't see anywhere in the PHP reference that session_destroy() in itself would ever throw an exception.

-joho
Reply


Messages In This Thread
$session->destroy() throws exception - by joho - 04-11-2024, 01:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB