header("location: file_name.php?fail=2") 是什么意思?

What does header("location: file_name.php?fail=2") mean?

一般来说,我知道它用于在执行操作后强制重定向(例如当我们请求 PHP 脚本写入数据库时​​)。

但我想知道 ?fail=2 的作用以及除此之外还有哪些其他选项。此外,header 是否可以用于执行不同任务但都必须重定向到同一页面的多个 PHP 脚本?

除了使用 header 之外,还有其他方法可以自动 重定向到该页面吗?

?fail=2(query string)表示发送查询字符串到URL.

fail = query string variable
2 = it's value

你可以使用GET方法来获取它

echo $_GET['fail']; //2

But I was wondering what the ?fail=2 does and what other options are there besides it.

您必须查看 file_name.php 的代码才能了解 $_GET['fail'] 参数的作用。它只是一个查询字符串参数,它可以用来做任何程序员希望它触发的事情。

作为有根据的猜测,我敢打赌 fail=2 会告诉脚本向用户的浏览器显示特定的错误消息。 fail=1 可能会显示不同的错误消息。

Are there other ways to automatically redirect to that page besides using the header?

您可以使用 JavaScript 或 <meta> 标签进行重定向。 header() 方法通常更好,因为搜索引擎可以理解它。