Link to home
Start Free TrialLog in
Avatar of Cesar Aracena
Cesar AracenaFlag for Argentina

asked on

Clean URL from GET variables

Hi guys,

I'm building a site without Smarty or any other framework so I'm making my own script to validate data, users selections, etc. An example would be when the user changes the language: check against the DB if the GET parameter contains a valid language and cookie him. That and more is being done in a file required before every page but once the visitor clicks on mysite.com/samepage/?lang=en I want the page to reload (for which I'm using $_SERVER['REQUEST_URI']), work on the DB and cookie stuff and send him to the same page but with a clean URL (i.e. mysite.com/samepage/).

What's the best method? regex?

Thanks in advance!
Avatar of Cesar Aracena
Cesar Aracena
Flag of Argentina image

ASKER

I found a solution by doing the following after I used the GET variables:

if ($_SERVER['QUERY_STRING'] != '') {
  unset($_SERVER['QUERY_STRING']);
  header('Location: '.$_SERVER['HTTP_REFERER']);
  die;
}

Open in new window

I would love to hear comments and specially it it's safe.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial