0

Possible Duplicate:
Clean URLs for search query?

I made a php webpage for checking the color code,here is the first four line

if(isset($_GET['c']))
$hex = $_GET['c'];
elseif(!isset($_GET['c']))
$hex = $_POST['c'];

and my htaccess have:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]{6})$ index.php?c=$1 [L]

if I type site.com/ffcdee it successfully show the color #ffcdee but if i use the input box:

<form action="">
<input type="text" name="c" >
<input type="submit" value="Search" id="search-submit">
</form>

it show site.com/?c=ffcdee, I tried change input name to other word,but the script not work anymore.. how can I remove the ?c= from the url?

Community
  • 1
  • 1
  • With a redirect, or updating the request URL per Javascript. – mario Oct 21 '12 at 16:24
  • one more problem:If I use the input box enter three digits color hex code it can show up the color(/?c=F00),but if I enter three digits color hex code in url(/F00) it not working. – user1727651 Oct 21 '12 at 16:25

1 Answers1

1

Just use the http post method instead of http get:

<form action="" method="post">
<input type="text" name="c" >
<input type="submit" value="Search" id="search-submit">
</form>

When using http post requests the query arguments are not passed coded inside the url, instead they are handed over as a separate "body" of the request. The content of that body is what you finally get presented inside php as the $_POST superglobal variable.

If you want to understand how that works use a network sniffer like wireshark to dump the http traffic. You will see and understand the difference between get and post.

arkascha
  • 41,620
  • 7
  • 58
  • 90