隐藏生成的URL中的参数

时间:2014-06-25 19:04:25

标签: php get

我有一个通过GET提交的表单,因为我需要它为每个提交的表单生成一个唯一的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参数。最好的方法是什么?

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>