我有一个用于提交简历的php页面。一旦他们点击提交,他们将所有帖子信息发送到mail.php
一旦发送邮件,我希望用户返回网站上的其他页面(工作机会所在的位置)
是否有任何类型的命令可以在mail.php完成其业务后用于重定向到不同的页面?
由于
答案 0 :(得分:8)
这是PHP中的标准重定向:
<?php
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: http://www.example.com' );
exit;
?>
但是,在您的情况下,301重定向行可能不是必需的。应该注意的是exit
是必要的,否则你的PHP脚本的其余部分将被执行,你可能不需要(例如,如果出现错误,你可能想要显示一些东西)。
此外,在将任何输出发送到浏览器(包括空行)之前,必须调用header
函数。如果您无法避免一些空白行,请将ob_start();
放在脚本的开头。
答案 1 :(得分:5)
header("Location: /yourpage.php");
答案 2 :(得分:2)
使用header()功能:
header('Location: http://example.com/new_loc/');
或
header('Location: /new_loc/'); // if it's within the same domain.
答案 3 :(得分:2)
在mail.php结尾处添加
header("Location: anotherpage.php");
请记住,在header()调用之前,您无法输出任何内容,以使重定向正常工作。
答案 4 :(得分:1)
在相关说明中,关于PHP头命令的一个重要事项,您必须确保在运行它的页面上显示任何内容之前运行此命令,否则它将无法工作。
例如,这不起作用:
<html>
<head>
</head>
<body>
Hello world
</body>
<?php header("Location: mypage.php"); ?>
</html>
但这会奏效:
<?php header("Location: mypage.php"); ?>
<html>
<head>
</head>
<body>
Hello world
</body>
</html>
基本上,如果在任何静态内容甚至HTML标记从脚本中吐出之前在PHP脚本中使用了header命令,那么header命令将只能工作。