PHP 另一个页面表单提交后自动刷新页面

PHP Auto refresh page after another page form submission

我目前有 3 个页面:index.php、Insertred.php andhomered.php

Homered 是一种在提交后更新到数据库的表单,Index.php 是一个显示结果的页面。 我搜索了一些关于自动刷新页面的内容,但都是定时刷新。

是否可以让 index.php 在 homered.php 提交时自动刷新? 目前它这样做: homered.php 提交按钮 > insertred.php > index.php

homered.php:(删除了 php 部分,因为它只是会话检查)

<html>

<head>
    <link rel="stylesheet" type="text/css" href="homered.css">                           
    </head>
<body>
<div class="centerimage">
<img src="images/anonymousfacepng.png" alt="Avatar" align="middle">
</div>
<div class="home-page">  
  <div class="form">
    <form class="home-form" action="insertred.php" method="post">
    <input type="text" placeholder="FTP Password" name="FTPBreach"/>
    <input type="text" placeholder="XP2 Victim IP" name="VictimIP"/>
    <input type="text" placeholder="XP2 Victim Password" name="VictimPass"/>
    <input type="text" placeholder="SQL Username" name="SQLUser"/>
    <input type="text" placeholder="SQL Password" name="SQLPass"/>
    <button>Submit</button>
      <p class="message"><a href="logoutred.php">logout</a></p>
    </form>
  </div>
</div>
</body>
<footer>
    © 
</footer>
</html>

Insertred.php:

    <?php
    $db = mysqli_connect('prjtest1', 'root', 'test', '165619z_database');
    if (!$db)
    {
        die('Could not connect: ' . mysql_error());
    }
    $currenttime = date('Y-m-d H:i:s');
    echo $sql="UPDATE indextableredupdated SET FTPBreach = '$_POST[FTPBreach]', VictimIP = '$_POST[VictimIP]', VictimPass = '$_POST[VictimPass]', SQLUser = '$_POST[SQLUser]', SQLPass = '$_POST[SQLPass]', message = '$_POST[message]', time = '$currenttime' WHERE user = '2'" ;

    $query = mysqli_query($db,$sql);

    if (!mysqli_query($db, $sql))
    {
        die('Error: ' . mysql_error());
    }

    if($query)
    {

    header("location: index.php");
    }
    ?>

不确定您是否需要 index.php 的代码,因为它很长。 TLDR;我需要 index.php 仅在 insertred.php

之后刷新

这实际上是不可能的。 PHP 是一种服务器端语言,仅在请求时执行一次。由于 PHP 的编译方式,无法制作监听器或类似的东西。
它执行一次,可能会回显任何数据等。但是当页面被客户端查看时,在页面再次刷新之前不会有服务器端代码 运行。

单击 here 观看教您 PHP 如何在 background/on 服务器

中工作的视频