Destroy a PHP session on clicking a link

mpsbhat picture mpsbhat · Jul 10, 2013 · Viewed 62.5k times · Source

Is this code valid?

<a href="#" onclick="<?php session_destroy();?>">Logout</a>

Answer

user2067005 picture user2067005 · Jul 10, 2013

Make a page called logout.php

Logout.php_____

<?php
Session_start();
Session_destroy();
header('Location: ' . $_SERVER['HTTP_REFERER']);

?>

Your page______

<a href="Logout.php">Logout</a>