开发者

php - How do I redirect a user based on their form input?

I want a simple form with one text box and a submit button. For example: If a user enters "foobar" into the text box and hits enter, they should be redirected to mysite.com/browse/foobar

Does anyone know how I can开发者_如何学运维 do this in php? thanks


Assuming name='q' for the text input

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


The Form:

<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']);

Note: this is not good practice but it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜