PHP iframe重定向到另一个页面


PHP iframe redirect to another page?

从现在开始,我试图在php不在自己的name.php页面上的情况下对其进行echo,而是在提交按钮下的index.html上。

当前html代码:

 <form autocomplete="off" action="test.php" method="post" target="iframe" accept-charset="UTF-8">
  <p>Passcode:</p>
  <input type="password" name="code"/><br>
  <input type="submit" value="Login" />
  <iframe name="iframe"></iframe>
</form>

当前php代码:

$testcode = ("123");
  } else if ($pass === $testcode) {
    header('location: test.html');
  } else {
    echo "Try Again!";
  }

这是可行的,除非它成功了,页面不会重定向到test.html,而是尝试在iframe中转到test.html。但是,如果我将表单目标设置为_self,它会重定向到test.html,但不会在iframe中回显"重试"。

那么,如果输入了正确的代码,我如何重定向到test.html,如果代码不正确,我如何在提交按钮下面打印"重试"呢?

使用php无法实现这一点。因为

PHP是一种服务器端语言。

打开新窗口是客户端操作

因此,您需要使用Jquery或javascript来实现这一点。