可以使用PHP来重定向

时间:2012-01-19 04:49:31

标签: php html

我有一个非常虚伪的PHP问题所以请耐心等待......

我如何使用PHP根据表单输入将用户重定向到特定页面?

例如,如果他们输入的是他们来自密歇根州而不是脚本会将他们重定向到www.site.com/michigan.php。

7 个答案:

答案 0 :(得分:5)

header("Location: http://example.com/");
exit;

答案 1 :(得分:1)


//assuming the data is from post
$from = $_POST['state']; // say Michigan
header("Location: http://www.site.com/{$from}.php");
exit;

答案 2 :(得分:1)

您可以像这样重定向。您可以选择在url中使用子变量来使其逐个状态。

header('Location: www.site.com/michigan.php');
exit;

答案 3 :(得分:1)

http://www.php.net/manual/en/function.header.php

手册页是你的朋友!

header()用于发送原始HTTP标头。有关HTTP标头的更多信息,请参阅»HTTP / 1.1规范。

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

<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
?> 

答案 4 :(得分:0)

http_redirect其他可能会有帮助,{{3p>

答案 5 :(得分:0)

<?php
//To redirect page of another site
header('Location:http://www.redirectTosite.com/');
?>

<?php
To redirect to anothe rpage of your website
header('Location:/yourPage.php');
?>

答案 6 :(得分:0)

完成数据库查询后,您应该重定向页面,以便在您按F5时不会重新提交表单数据,并且数据库中会有重复的条目

所以在插入更新或删除后重定向页面。

 <?php
header('Location:test.php');
?>
相关问题