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

时间:2018-12-10 07:29:02

标签: php html mysql apache2

我目前有3页:index.php,Insertred.php和homered.php

Homered是一种表单,在提交后会更新数据库,而Index.php是显示结果的页面。 我已经完成了一些有关自动刷新页面的搜索,但是所有这些都是计时器刷新。

是否有可能使homered.php提交时index.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;我只需要在insertred.php

之后刷新index.php

1 个答案:

答案 0 :(得分:0)

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

点击here观看一段视频,该视频向您介绍PHP在后台/服务器上的工作方式