Tuesday, 14 June 2016

Removing a querystring in PHP and reloading the page

Whats the best way in PHP to reload the page I'm on with all the previous query string values removed from the URL?
 <?php
$pageRefreshed = isset($_SERVER['HTTP_CACHE_CONTROL']) &&($_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0' ||  $_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache'); 
if($pageRefreshed == 1){
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = parse_url($url, PHP_URL_PATH);
if(count($_GET)) { 
header('Location: '.$url);
die();
}
}


?> 

0 comments:

Post a Comment