Toast Notification Appears on Every Page After Login Failure in CodeIgniter

I’m facing an issue with toast notifications in my CodeIgniter app. After a failed login attempt, the error message is displayed correctly using Toastr. However, this message keeps appearing on every page after the login attempt, even after navigating or refreshing the page.

I’ve tried using flashdata to show the error message, but the toast notification keeps appearing on all pages until the session expires or I manually clear the session.

Here’s my login function:

$login_status = $this->validate_login($email, $password);`
if ($login_status == 'success') {`
    redirect(site_url('dashboard'), 'refresh');`
} else {
    $this->session->set_flashdata('error_message', get_phrase('login_failed'));`
    redirect(site_url('login'), 'refresh');
}

Logout Function:

    $this->session->sess_destroy();
    $this->session->set_flashdata('logout_notification', 'logged_out');
    redirect(site_url('login'), 'refresh');
}

In includes-bottom.php:

    <script>
        toastr.error('<?php echo $this->session->flashdata('error_message');?>');
    </script>
<?php } ?>

Session Config:

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

I’ve ensured the flash message is unset after use, and session regeneration is done. However, the issue persists where the toast notification keeps appearing across all pages after a failed login.

Has anyone faced this issue before? What am I missing here?

I tried using flashdata to display the error message for login failure and unset the session after showing the message. I also ensured the session is regenerated and cleared on logout. I expected the toast message to only appear once when the login fails and not persist across multiple pages or after a page refresh. However, the issue persists, and the toast message keeps showing on every page even after navigating or refreshing the page.