views:

90

answers:

3

I have a url that is constructed using get variables like

location.href = this.href +'?type='+ escape($('#type_of_station').html()) + '&count='+ escape($('.number_changer').attr("id").slice(-1));

which gives me a url like the following

http://posnation.com/pre_config/pre_config_step_2.php?type=Grocery&count=2 

on the following page I grab the variables via PHP

<p id="type_of_station" class="text left"><?php $_GET['type'] != "" ? print str_replace("_", " ", $_GET['type']) : print "Food Pos System" ?></p>

This works great but the url is kind of ugly. Is there a way to maybe hide this and still have the get variables available to me on the next page

A: 

Either use $_POST instead of $_GET, or save them in a session and go to the next page.

EDIT: That is if you really want to completely hide the variables. As the others are suggesting: it's better to use mod_rewrite to make it look nicer, without hiding the data.

captaintokyo
+1  A: 

You want to POST your variables to the server rather than sending them as GET requests.

In PHP you can access the variables POST-ed with the $_POST variable.

Simple form:

form.php

<form action="process.php" method="POST">
   username: <input type="text" name="username" value="" /><br/>
</form>

The 'username' POST-ed could then be accessed in the process.php file by

process.php

echo $_POST['username'];

Unlike GET requests, values sent to the server are not shown in the URL.

So Over It
NEVER use POST where GET should be, son. These methods are not interchangeable.
Col. Shrapnel
@Col. Shrapnel: How do you know GET should be used here?
Josh
No one said they were interchangeable. But it is one way to approach the problem presented.
So Over It
If you use post you can't access pages directly using the URL.
Stian
@Stian: true, but not everything is about accessing the URL or SEO. Some things don't need to be accessed again or permalinked.
So Over It
+2  A: 

To make url look nice is one thing.
To hide url data is another. Never hide anything. Or you will make your site unusable.

Col. Shrapnel
This depends on the context, but is often true.
Pekka
I'm sorry, but in the example provided I don't see how using POST instead of GET makes the site unusable. It does prevent bookmarking of the URLs, but these URLs seem to be steps in a configuration process. Major sites like Dell use POST for configuration of their systems. And if bookmarking is desired, a better approach with complex data would be a "Bookmark This"/permalink solution.
Josh