2010-04-14 105 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

相關問題