退出按钮php [英] Logout button php
本文介绍了退出按钮php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此代码,需要添加退出按钮的代码,任何人都可以为退出用户的退出按钮写出代码,我读过一些有关destroy session的内容,但不知道如何编写代码出来,谢谢!
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>
推荐答案
代替按钮,放一个链接并将其导航到另一个页面
Instead of a button, put a link and navigate it to another page
<a href="logout.php">Logout</a>
然后在logout.php
页面中使用
session_start();
session_destroy();
header('Location: login.php');
exit;
这篇关于退出按钮php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文