Vlad
Vlad

Reputation: 1797

How to redirect using PHP and unset any existing get parameters

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?

Upvotes: 0

Views: 7771

Answers (4)

Fahim Faisal
Fahim Faisal

Reputation: 11

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 ");
   }

Upvotes: 0

Harry B
Harry B

Reputation: 2972

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

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

Upvotes: 0

Kode Plus
Kode Plus

Reputation: 706

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

In your Previus page:

<?php if(isset($_GET)) {unset($_GET);} ?>

Upvotes: 0

Peon
Peon

Reputation: 8020

header( "Location: http://www.your-site.com/" );
die;

Upvotes: 5

Related Questions