2014-06-25 35 views
0

我有一個通過GET提交的表單,因爲我需要它爲每個提交的表單生成一個唯一的URL。目前生成的URL看起來像下面的例子:隱藏從生成的URL中獲取參數

http://example.com/index.php?StoreID=1&value=22000&orderID=HEQ6FMYH&option1=0&option2=0

<form name="form1" action="http://example.com/index.php" method="get"> 
    <input type="text" name="storeID" value="1" /> 
    <input type="text" name="value" value="22000" /> 
    <input type="text" name="orderID" value="<?php echo string_random(8);?>" /> 
    <input type="text" name="option1" value="0" /> 
    <input type="text" name="option2" value="0" /> 
    <input type="submit" /> 
</form> 

我需要做的是隱藏生成的URL的GET參數。什麼是最好的方式來做到這一點?

+0

爲什麼不使用POST而不是GET? –

+0

你爲什麼要隱藏它?您無法使用GET加載一個網址,並向用戶顯示另一個網址。如果您使用POST,只會顯示基本URL –

+0

歡迎使用StackOverflow! – pixelistik

回答

0

您可以將表單更改爲POST,並將您的唯一字符串添加到該操作。現在所有的表單數據都將不在URL中,但會傳遞給接收頁面,並且生成的URL本身將是唯一的。

<form name="form1" action="http://example.com/index.php?orderID=<?php echo string_random(8);?>" method="post"> 
    <input type="text" name="storeID" value="1" /> 
    <input type="text" name="value" value="22000" /> 
    <input type="text" name="option1" value="0" /> 
    <input type="text" name="option2" value="0" /> 
    <input type="submit" /> 
</form> 
+0

這可能是OP想要的,我不知道,因爲問題不是很清楚。不知道是否OP想要顯示隨機數(他們可能) –

+0

我已經在操作中添加了一個randon變量並使用了POST。謝謝,邁克。 – Marcelo

+0

很高興能幫到你! –

0

一種方法是使用POST,如其他人所建議的。 您也可以使用Apache來解決問題。 您需要在根中創建.htaccess文件。

Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^index.php /index.php?StoreID=$1&value=$2&orderID=$3&option1=$4&option2=$5 [NC] 

在這裏你可以找到有用的東西有關mod_rewrite的:

http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

http://www.askapache.com/htaccess/modrewrite-tips-tricks.html

http://www.sitepoint.com/apache-mod_rewrite-examples-2/

但正如我以前說過,改變對GET和POST你完成:

<form name="form1" action="http://example.com/index.php" method="post"> 
    <input type="text" name="storeID" value="1" /> 
    <input type="text" name="value" value="22000" /> 
    <input type="text" name="orderID" value="<?php echo string_random(8);?>" /> 
    <input type="text" name="option1" value="0" /> 
    <input type="text" name="option2" value="0" /> 
    <input type="submit" /> 
</form>