0

How can I redirect back to my starting page with PHP to clear my GET parameters? I have made a form that once filled out will be sent to a .php file that handles the GET data and saves it to a database. After that I am using header("Location: redirect.php") which then again redirects to ("Location: main.php"). After these are both executed I get sent back to something that looks like the main page but instead I get the url formSaver.php?alot=ofparamters when I get back. If I click something I will get into the main.php part and it works. But if someone hits F5 before they click anything I will get double entries. Anyone know what I have done wrong?

4 Answers 4

5
header( "Location: http://www.your-site.com/" );
die;
7
  • Still got the get parameters in the url, but thanks anyway :)
    – Vlad
    Commented Jul 19, 2012 at 7:44
  • After hard location change, there is no way you can have parameters in url, unless you are redirecting with them, meaning "Location: http://www.your-site.com/?etc=1"
    – Peon
    Commented Jul 19, 2012 at 12:31
  • header("Location: mydomain.com/myfile.php"); Still get it back with all the parameters, must be some sort of crash between the different languages or something I figure
    – Vlad
    Commented Jul 19, 2012 at 12:42
  • Did you add die; after redirect?
    – Peon
    Commented Jul 19, 2012 at 12:47
  • yeah, I even had a middle page that did only session_start, header redirect (Again) and die (again). O_o Just have to stick to it then :/
    – Vlad
    Commented Jul 19, 2012 at 13:13
0

header( "Location: your-previous-page" );

In your Previus page:

<?php if(isset($_GET)) {unset($_GET);} ?>
1
  • Seems like it should work but I still get all the $_GET parameters in the url. Weird.
    – Vlad
    Commented Jul 19, 2012 at 7:43
0

If you don't want to hardcode the current host or path:

$uriParts = explode('?', $_SERVER['REQUEST_URI'], 2);
header("Location:" . $uriParts[0]);
0

I think $_GET method is available all the time. you can just clear those parameters by

unset($_GET);

Whether you should check by isset operation. Like;

if(isset($_REQUEST['logout'])){ 
      session_destroy();
      header("Location: Your page ");
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.