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_log( basename( __FILE__ ) . ' (' . __FUNCTION__ . '): Session already active, re-directing to /' );
return( $this->response->redirect( base_url() ) );
}
$ip_address = $this->request->getIPAddress();
if ( empty( $ip_address ) ) {
error_log( basename( __FILE__ ) . ' (' . __FUNCTION__ . '): Missing or invalid IP address "' . $ip_address . '", re-directing' );
$session->destroy();
return( $this->response->redirect( base_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