注销后 点击浏览器后退 又回到登陆后的界面
有三个界面 logon.php / checklogon.php / detail.php / logout.php
logon.php - session_start() 还有包括登陆form等的其他静态html,点登陆了按钮后跳转到checklogon.php.
checklogon.php - 连接数据库并返回用户信息。如果成功$_SESSION['user'] = 用户的相关信息,并跳转到detail.php。
$user = UserBusiness::GetUser($_POST["username"], $_POST["password"]);if($user == null){ header("location: /index.php"); exit;}$_SESSION['user'] = $user;
detail.php - 上面包括了一个注销link,单击后会调用logout.php.
logout.php -
<?php session_destroy(); header("Cache-Control: private, must-revalidate, no-store"); header("Pragma: no-cache"); header("Expires: Sat, 26 Aug 1997 05:00:00 UTC"); header("location: /logon.php"); exit();?>
当点击了logout按钮后,页面到了登陆界面,但是点击浏览器的后退按钮后(IE 8/Firefox),前一个detail界面又显示了。 请问大家如何解决。
当点击后退按钮后,detail.php里面的代码并没有执行,应该是缓存的detail.php有显示了出来。
回复讨论(解决方案)
你这个得贴出detail.php的验证部分来看看
<?php echo('<a href="/Logout.php">Logout</a>');?>
你这个得贴出detail.php的验证部分来看看 贴上了
<?php echo('<a href="/Logout.php">Logout</a>');?>
这个就是?
你里边都没有验证session是否存在的代码,即使你销毁了session又有什么用
修改登陆的PHP,加入如下代码。
<?php session_start(); //使用session存储用户信息 if(isset($_POST["username"])) //数据库中读取username用户名 { $ss_user_id=""; //利用User累的IsValid()方法判断所输入的用户名和口令是否正确 require_once("userclass.php"); //获取用户信息的类 $user=new User(); //如果正确,转到网站首页 if($user->IsValid($_POST["username"],$_POST["password"],$ss_user_id)) { $_SESSION["ss_user_id"]=$ss_user_id; //用户ID echo "<script language='javascript'>"; echo " location='index.php';"; echo "</script>"; } //如果不正确,刷新页面 else { echo "<script language='javascript'>"; echo " alert('用户名或密码错误');"; echo "</script>"; } }?>
修改checklogin.php或者新建一个check.php加入验证用户是否存在代码。
<?php session_start(); if(! isset($_SESSION['ss_user_id'])) //判断是否存在用户ID { echo "<script language='javascript'>"; echo "alert('您的用户无权进行此操作!');"; echo "location='login.html';"; echo "</script>"; exit; }?>
在除登陆和退出页面以外的其他页面文件头处都加上上面这段代码。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
