用户按下注销后如何停止后退按钮

时间:2016-10-24 01:28:30

标签: php

的login.php 我只是想在用户注销后阻止用户并按下后退按钮,他仍然会注销...在用户注销后我的项目的当前状态并按回按钮他将返回到最后一页并仍然登录

<!DOCTYPE HTML>
 <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=MS932">
     <title>Login Page</title>
   <link rel ="stylesheet" type="text/css" href="style.css">
</head>

 <body>
<div id ="frm">
<form action="process.php" method="post" >
   <p>
          <label>Username:</label>
          <input type="text" id="email" name="user" required/>
   </p>
   <p>
          <label>Password:</label>
          <input type="password" id="pass" name="pass" required/>
   </p>
   <p>

          <input type="submit" id="btn" value="Login"/>
   </p>


</form>
</div>
</body>

process.php

  <?php 
 $username = $_POST['user'];
 $password = $_POST['pass'];

  $username = stripcslashes($username);
  $password = stripcslashes($password);
  $username = mysql_real_escape_string($username);
  $password = mysql_real_escape_string($password);

 mysql_connect("localhost","root","");
  mysql_select_db("testproduct");

  $result = mysql_query("SELECT * FROM tbluser where email = '$username' and  pass='$password'")or  die("Failed to query database".mysql_error());
$row = mysql_fetch_array($result);
  if($row['email'] == $username && $row['pass'] == $password){
echo "<script>window.location.assign('index.php');</script>";
 }else{

   echo "<script>alert('Login was unsuccessful, please check your username   and password')</script>";
   echo "<script>window.location.assign('login.php');</script>";
   return false;
 }
 ?> 

logout.php

  <?php 
  session_start();
 session_destroy();
 $_SESSION = array();
 header("location: login.php");
  ?>

1 个答案:

答案 0 :(得分:0)

在用户登录时初始化<?php require 'dbconnect.php'; ?> if (isset($_POST['suEmail'])) { echo "<script type='text/javascript'>alert('got');</script>"; $suFirstName = mysqli_real_escape_string($_POST['suFirstName']); $suLastName = mysqli_real_escape_string($_POST['suLastName']); $suEmail = mysqli_real_escape_string($_POST['suEmail']); $suPassword = mysqli_real_escape_string($_POST['suPassword']); $suDisplayName = mysqli_real_escape_string($_POST['suDisplayName']); $code = substr(md5(mt_rand()),0,15); $query = $connection->query("INSERT INTO users (firstName,lastName,email,password,displayName,confirmCode,verified)Values('{$suFirstName}','{$suLastName}','{$suEmail}','{$suPassword}','{$suDisplayName}','{$confirmCode},'{$verified}')"); } 并在注销时将其销毁。每次您转到session variable,都会检查index.php是否存在或session variable是否存在。

<强> http://php.net/manual/en/ref.session.php

<强> process.php

successful login

<强>的index.php

 <?php 
 session_start();

 $username = $_POST['user'];
 $password = $_POST['pass'];

  $username = stripcslashes($username);
  $password = stripcslashes($password);
  $username = mysql_real_escape_string($username);
  $password = mysql_real_escape_string($password);

 mysql_connect("localhost","root","");
  mysql_select_db("testproduct");

  $result = mysql_query("SELECT * FROM tbluser where email = '$username' and  pass='$password'")or  die("Failed to query database".mysql_error());
$row = mysql_fetch_array($result);
  if($row['email'] == $username && $row['pass'] == $password){
  $_SESSION['un'] = $username;
echo "<script>window.location.assign('index.php');</script>";
 }else{

   echo "<script>alert('Login was unsuccessful, please check your username   and password')</script>";
   echo "<script>window.location.assign('login.php');</script>";
   return false;
 }
 ?>