如何使用PHP脚本重定向?如何使用PHP脚本将用户从他们输入的url重定向到不同的网页/url?
该代码不起作用:/header((标记也不起作用。
if(/*do something, nevermind*/)) {
mail($to, $subject, $message, $headers);
echo "<p> Form sended </p>";
header('<meta http-equiv = "refresh" content = "0; url = https://faunaservice.pl">');
exit;
}
使用它来回显您的消息,然后在几秒钟后重定向到另一个页面。
if(1 == 1 ) {
mail($to, $subject, $message, $headers);
echo "
<p> Form sended </p>
<script>
setTimeout(function(){
window.location.href = 'https://example.com/';
}, 5000);
</script>
";
exit;
}
您有两个选项:
标头重定向
header('Location: http://whatever.com');
根据您的PHP配置,您可能不想在此命令之前回显任何内容,因为回显后可能会立即将标头发送到浏览器,并且发送新标头为时已晚。
刷新元数据
echo '<meta http-equiv="refresh" content="0; url=http://whatever.com">';
这必须位于html文档的<head>
部分
请注意,在您的代码中,发送元刷新标头是无效的。它要么是重定向头,要么是html头中的刷新元。