PHP 在订阅后不会重定向


PHP not redirecting after submision

<?php
    error_reporting(0);
    if(isset($_POST['submit'])){
        $additionalIDs = array("williamhew","anthon9","geroyi");
        $rA = array_rand($additionalIDs,1);
        $merchantNick   = ".membership.com";
        $gen_link = $additionalIDs[$rA].$merchantNick;
        header("Location: http://$gen_link");
    }
?>
<input type ="submit" name="submit"  ></input>

我不确定为什么在我点击提交后它没有重定向。这段代码有什么问题吗?:(,我需要你们的帮助。

编辑:

使用它也不能重定向,

<?php
    error_reporting(E_ALL);
    if(isset($_POST['submit'])){
        ob_start();
        header("Location: http://www.facebook.com");
        exit;
    }

尝试使用 param method="post" 将 INPUT 元素包装在 <form> 标签中,如下所示:

<form method="post">
      <input type ="submit" name="submit" />
</form>

顺便说一下,INPUT 是一个自结束标签,所以你可以这样写它而不是<input type ="submit" name="submit" ></input><input type ="submit" name="submit" />

你要么在标头之前输出一些东西,在这种情况下它不会重定向。

请记住,在任何实际输出之前必须调用 header(( 通过普通 HTML 标记、文件中的空行或从 PHP 发送。 读取包含或要求的代码是一个非常常见的错误 函数或其他文件访问函数,并且具有空格或空 在调用 header(( 之前输出的行。同样的问题 使用单个 PHP/HTML 文件时存在。

或者链接本身无效。这并非不可能。

试试这个

使用 window.location 而不是标头位置

<?php
echo "<script>window.location.href='index.php'</script>";
} ?>

你只需要添加

<form method="post">
    <input type ="submit" name="submit"></input>
</form>