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
header( "Location: http://www.your-site.com/" );
die;
-
-
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"
– PeonCommented 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– VladCommented Jul 19, 2012 at 12:42
-
-
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 :/– VladCommented Jul 19, 2012 at 13:13
header( "Location: your-previous-page" );
In your Previus page:
<?php if(isset($_GET)) {unset($_GET);} ?>
-
Seems like it should work but I still get all the $_GET parameters in the url. Weird.– VladCommented Jul 19, 2012 at 7:43
If you don't want to hardcode the current host or path:
$uriParts = explode('?', $_SERVER['REQUEST_URI'], 2);
header("Location:" . $uriParts[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 ");
}