Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 我再重新提问一下 那个页面跳转的问题

我再重新提问一下 那个页面跳转的问题

Jun 23, 2016 pm 01:15 PM

可能我没说清  我再发一遍  我做的这个想要的效果是这样的:有一个帖子列表页A页面    从A页面点击一个标题就会跳转到这个主题页面B页面  注意这里是跳转过去的  不是打开的一个新的标签  我在B页面里面发表回复再点击浏览器的返回按钮就可以返回到A页面    这个是我想要的效果 但是现在我做的这个有个bug   就是在B页面发表完回复后点击一次浏览器的返回按钮不能回到A页面  还是留在B页面  再点击一次才能回到A页面  如果在B页面提交两次回复 需要点击三次才能回到A页面   搞不懂为什么会这样啊  
 
b页面的代码如下:
tieba3.php
;
nbsp;html>







include "cookie.php";
?>


  

      $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
    $title=$_GET['id'];
    $stmt=$pdo->prepare("select id,title,content from topic where id=?");
    $stmt->execute(array($title));
    $res=$stmt->fetchall(PDO::FETCH_ASSOC);
    foreach($res as $v){
      echo ''.$v['content'].'';
    }
  ?>
     $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
   $id2=$_GET['id'];
   $stmt=$pdo->prepare("select id,reid,content from reply where reid=?");
   $stmt->execute(array($id2));
   $res1=$stmt->fetchall(PDO::FETCH_ASSOC);
    foreach($res1 as $v2){
      echo $v2['content'];
     }
   ?>
  

  

    


     ">
     " >
      
      
  

  





提交回复插入到数据库的页面 tieba4.php
if(isset($_POST['reid'])){
  $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
 $stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");
 $stnt->execute($_POST);
header("location:http://localhost/tieba3.php?id=".$_POST['reid']);
}
?>


回复讨论(解决方案)

header后写个exit():试试看。

header后写个exit():试试看。


是这样吧 试了一下 不行
header("location:http://localhost/tieba3.php?id=".$_POST['reid']);
exit();

检查$_POST['reid']是否为空而出notice,在header前加ob_clean();看看

检查$_POST['reid']是否为空而出notice,在header前加ob_clean();看看


不是空的  都是正常的

A 点击连接 进入 B :历史列表 A
B 提交到 C             :历史列表 A B
C 重定向                 :历史列表 A B
所以延历史列表回到 A,需要 2 次 后退

A 点击连接 进入 B :历史列表 A
B 提交到 C             :历史列表 A B
C 重定向                 :历史列表 A B
所以延历史列表回到 A,需要 2 次 后退



那么怎么解决呢? 我是新手没有遇到过这样的问题

一个方案:
tieba4.php

<?phpif(isset($_POST['reid'])){  $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");  $stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");  $stnt->execute($_POST);  echo "    <script>    history.go(-1);    location = 'tieba3.php?id={$_POST['reid']';    </script>";}?>
Copy after login
现在流行 ajax,页面已经不会跳转了
自然页不会依赖浏览器的 后退 按钮

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

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.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

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 automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

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.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

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

See all articles