我目前有 3 个页面:index.php、Insertred.php 和 homered.php
Homered 是一种在提交后更新到数据库的表单,Index.php 是一个显示结果的页面。
我已经搜索了一些关于自动刷新页面的内容,但它们都是定时器刷新。
是否可以让 index.php 在 homered.php 提交时自动刷新? 目前它这样做: homered.php 提交按钮 > insertred.php > index.php
homered.php:(删除了 php 部分,因为它只是 session 检查)
<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
最佳答案
这实际上是不可能的。 PHP 是一种服务器端语言,仅在请求时执行一次。由于 PHP 的编译方式,无法创建监听器或类似的东西。
它执行一次,可能会回显任何数据等。但是当页面被客户端查看时,在页面再次刷新之前不会运行服务器端代码。
点击here观看视频,了解 PHP 如何在后台/服务器上工作
关于PHP 在另一个页面表单提交后自动刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53701199/