An additional issue in this Logout, in addition to what has already been mentioned by @Papacharlie, is that any link out to the logout page complicates the user experience. The way it is, just an accidental click on the history or a wrong autocomplete and the guy keeps "escaping" the session "dislocating" unintentionally.
Also, some malicious "competitor" could force its users to lose their session constantly with a mere invisible link on other sites (example: <script src="http://seusite/caminhodologout">
).
Ideal if this logout page received a parameter that identified the session. If you receive, log out, if you do not receive, it shows "Confirm logout?" and in SIM uses a link with the parameter, so an "old" pro logout link would not work.
Simplified example of solution:
Logout link:
echo '<a href="doLogout.php?token='.md5(session_id()).'">Sair</a>';
// sim, MD5 é seguro suficiente nesse contexto (e é apenas exemplo).
Logout page:
session_start();
$token = md5(session_id());
if(isset($_GET['token']) && $_GET['token'] === $token) {
// limpe tudo que for necessário na saída.
// Eu geralmente não destruo a seção, mas invalido os dados da mesma
// para evitar algum "necromancer" recuperar dados. Mas simplifiquemos:
session_destroy();
header("location: http://exemplo.com.br/index.php");
exit();
} else {
echo '<a href="doLogout.php?token='.$token.'>Confirmar logout</a>';
}
Yes, if the login only uses sessions, they should be destroyed. If there is a cookie, they should also be destroyed.
– Papa Charlie