2014-06-25 34 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>