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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?