douzizang7783 2017-06-18 07:16
浏览 130
已采纳

如何在我的PHP中实现注销按钮?

I'm trying to figure out how to implement a Log Out button into my code, but can't seem to figure out how to do it. Here is the code for my Log In page and Index page.

Index Page HTML

<?php
include("connectDatabase.php");
include("products.php");
?>
<?php
require "logincheck.php";
?>

<html>
<head>
<br><br>
<a href="resetPassword.php">Reset Password Page</a><br><br>
<a href="login.php">Login Page</a><br><br>
<a href="forgotPassword.php">Forgot Password Page</a><br><br>
<a href="logincheck.php">Login Check Page</a><br><br>
<a href="register.php">Register Page</a><br><br>

</head>
<body>
    <h1> Small IT Business <h1>
    Welcome <?php echo $_SESSION["email"] ?>.
</body>
</html>

Login In Page PHP

<?php
session_start();

if (isset ($_SESSION["email"]) && isset($_SESSION["loggedIn"])) {
    header("Location: index.php");
    exit();
}
if(isset($_POST["logIn"])) {
    $connection =  new mysqli("localhost", "root", "", "membershipsystem");

$email = $connection->real_escape_string($_POST["email"]);
$password = sha1($connection->real_escape_string($_POST["password"]));

$data = $connection->query("SELECT firstName FROM users WHERE 
email='$email' AND '$password'");

if($data->num_rows > 0) {
       $_SESSION["email"] = $email;
       $_SESSION["loggedIn"] = 1;


       header("Location: index.php");
       exit();
}else{
        echo "Please check your imputs!";
}
}
?>
<html>
<body>
    <form actions="login.php" method="post"> 
        <input type="text" name="email" placeholder="Email"/><br />
        <input type="password" name="password" placeholder="Password"/><br 
/>
        <input type="submit" value="Log In" name="logIn" />
</body>
</html>
  • 写回答

3条回答 默认 最新

  • dongyi6195 2017-06-18 07:20
    关注

    Create a logout.php and destroy the session there

    <?php
    session_start();
    session_destroy();
    echo 'You have been logged out';
    

    Place logout link in all required pages.

    <a href='logout.php'>Log out</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真