e non puoi aggiungere un
Codice PHP:
header("Location: index.php"); 
subito dopo tutte le operazionid di chiusura?