2010-04-14 101 views

回答

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

注:这是不好的做法,但它的工作原理。

+0

谢谢,这就是我所追求的。但我担心这不是“好习惯”。有没有更好的办法? – Steven 2010-04-14 21:49:17

+0

看看mod_rewrite。这是大多数网站用来获取“干净”URL的原因。 – Samuel 2010-04-14 21:56:52

+0

更好的方法是只允许$ _GET ['q']中的字母数字字符 - 这可以用$ q = preg_replace(“/ [^ a-zA-Z0-9 \ s] /”,'', $ _GET [ 'q']); – 2010-04-14 22:38:36

4

假设name='q'文本输入

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

对不起,但我的意思是“foobar”意思是用户想要输入的任何字 – Steven 2010-04-14 21:40:04

+0

http://uk3.php.net/urlencode加上一小串字符串连接,你就在那里。 – Quentin 2010-04-14 21:41:09

+0

对不起,但我不是“那里”呢。你能详细说明吗?谢谢 – Steven 2010-04-14 21:44:39

相关问题