开发者

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

开发者 https://www.devze.com 2022-12-27 11:42 出处:网络
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

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

精彩评论

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