logout button php code example

Example 1: logout in php

<?php
if(isset($_GET['logout'])) {
    session_destroy();
    unset($_SESSION['uname']);
    header('location:login.php');
}
?>

Example 2: logout in php

if(isset($_GET['logout'])) {
    session_destroy();
    unset($_SESSION['username']);
    header('location:login.php');
}

Example 3: logout php code

<?php
session_start();
?>
<html>
<head>
<title>User Login</title>
</head>
<body>

<?php
if($_SESSION["name"]) {
?>
Welcome <?php echo $_SESSION["name"]; ?>. Click here to <a href="logout.php" tite="Logout">Logout.
<?php
}else echo "<h1>Please login first .</h1>";
?>
</body>
</html>

Tags:

Php Example