php - 如何根据表单输入重定向用户?

时间:2010-04-14 21:35:02

标签: php forms

我想要一个带有一个文本框和一个提交按钮的简单表单。例如:如果用户在文本框中输入“foobar”并按Enter键,则应将其重定向到mysite.com/browse/foobar

有谁知道我怎么能在PHP中做到这一点?感谢

2 个答案:

答案 0 :(得分:4)

假设文本输入为name='q'

<?php
    if ($_GET['q'] === "foobar") {
        header("Location: http://example.com/browse/foobar");
    }
?>

答案 1 :(得分:1)

表格:

<form action="index.php" method="get">
<input type="text" name="q" />
<input type="submit" />
</form>

的index.php

header("Location: http://example.com/browse/".$_GET['q']);

注意:这不是好习惯,但它有效。

相关问题