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

如何在我的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>

图片转代码服务由CSDN问答提供 功能建议

我正在试图弄清楚如何在我的代码中实现一个Log Out按钮, 但是看起来不行 弄清楚如何做到这一点。 以下是我的登录 页面和索引页面的代码。

索引页面HTML

 &lt;?php 
include(“  connectDatabase.php“); 
include(”products.php“); 
?&gt; 
&lt;?php 
require”logincheck.php“; 
?&gt; 
 
&lt; html&gt; 
&lt; head&gt  ; 
&lt; br&gt;&lt; br&gt; 
&lt; a href =“resetPassword.php”&gt;重置密码页&lt; / a&gt;&lt; br&gt;&lt; br&gt; 
&lt; a href =“login.php”&gt  ;登录页面&lt; / a&gt;&lt; br&gt;&lt; br&gt; 
&lt; a href =“forgotPassword.php”&gt;忘记密码页&lt; / a&gt;&lt; br&gt;&lt; br&gt; 
&lt; a href =“  logincheck.php“&gt;登录检查页&lt; / a&gt;&lt; br&gt;&lt; br&gt; 
&lt; a href =”register.php“&gt;注册页&lt; / a&gt;&lt; br&gt;&lt; br&gt; 
  
&lt; / head&gt; 
&lt; body&gt; 
&lt; h1&gt; 小型IT业务&lt; h1&gt; 
欢迎&lt;?php echo $ _SESSION [“email”]?&gt;。
&lt; / body&gt; 
&lt; / html&gt; 
   
  
 

登录页面PHP

 &lt;?php 
session_start(); 
 
if(isset($ _SESSION [“email”])&amp;&amp;  ; isset($ _ SESSION [“loggedIn”])){
 header(“Location:index.php”); 
 exit(); 
} 
if(isset($ _ POST [“logIn”])){  
 $ connection = new mysqli(“localhost”,“root”,“”,“membershipsystem”); 
 
 $ email = $ connection-&gt; real_escape_string($ _ POST [“email”]); 
 $  password = sha1($ connection-&gt; real_escape_string($ _ POST [“password”])); 
 
 $ data = $ connection-&gt; query(“SELECT firstName FROM users WHERE 
email ='$ email'AND'  $ password'“); 
 
if($ data-&gt; num_rows&gt; 0){
 $ _SESSION [”email“] = $ email; 
 $ _SESSION [”loggedIn“] = 1; 
 \  n 
 header(“Location:index.php”); 
 exit(); 
} else {
 echo“请检查你的imputs!”; 
} 
} 
?&gt; 
&lt;  html&gt; 
&lt; body&gt; 
&lt; form actions =“login.php”method =“post”&gt;  
&lt; input type =“text”name =“email”placeholder =“Email”/&gt;&lt; br /&gt; 
&lt; input type =“password”name =“password”placeholder =“Password”/  &gt;&lt; br 
 /&gt; 
&lt; input type =“submit”value =“登录”name =“logIn”/&gt; 
&lt; / body&gt; 
&lt; / html&gt; 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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条)

相关推荐 更多相似问题