Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logout button php

Tags:

php

logout

I have this code and need the code to add a logout button, can anyone write out the code for a log out button that will log out the user, I read something about destroy session but do not know how to write the code out, thank you!

<?php
    include 'connection.php';
    //start of checking if user is logged in code
    if (!valid_credentials) {
    header('Location: login.php');
    exit();
    }

$_SESSION['user'] = 'username';


if (!isset($_SESSION['user'])) {
    header('Location: login.php');
    exit();
}
    //end of logged in code and starting a session

$query = "SELECT * FROM people";
$result = mysql_query($query);
While($person = mysql_fetch_array($result)) {
    echo "<h3>" . $person['Name'] . "</h3>";
    echo "<p>" . $person['Description'] . "</p>";
    echo "<a href=\"modify.php?id=" . $person['ID']. "\">Modify User</a>";
    echo "<span> </span>";
    echo "<a href=\"delete.php?id=" . $person['ID']. "\">Delete User</a>";
}
?>
<h1>Create a User</h1>
<form action="create.php" method="post">
    Name<input type ="text" name="inputName" value="" /><br />
    Description<input type ="text" name="inputDesc" value="" />
    <br />
    <input type="submit" name="submit" />
</form>
like image 948
crusader1223 Avatar asked Aug 31 '12 05:08

crusader1223


1 Answers

Instead of a button, put a link and navigate it to another page

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

Then in logout.php page, use

session_start();
session_destroy();
header('Location: login.php');
exit;
like image 106
asprin Avatar answered Oct 24 '22 23:10

asprin