remove GET parameter in URL after processing is fi

2019-01-24 02:11发布

I have url like this http://localhost/join/prog/ex.php

When i use GET method the url address like this http://localhost/join/prog/ex.php?name=MEMORY+2+GB&price=20&quantity=2&code=1&search=add

My question is : so, I still use the GET method but I want to after processing in GET method is finished, I want to the url back(remove parameter) into http://localhost/join/prog/ex.php, as previously (not using POST method). How can i do it?

标签: php html url get
4条回答
ら.Afraid
2楼-- · 2019-01-24 02:39

Put this in your HTML file (HTML5).

<script>    
    if(typeof window.history.pushState == 'function') {
        window.history.pushState({}, "Hide", "http://localhost/join/prog/ex.php");
    }
</script>

Or using a backend solution using a session for instance;

<?
    session_start();
    if (!empty($_GET)){
        $_SESSION['got'] = $_GET';
        header('Location: http://localhost/join/prog/ex.php');
        die;
    }
    else{
        if (!empty($_SESSION['got'])){
            $_GET = $_SESSION['got'];
            unset($_SESSION['got']);
        }

        //use the $_GET vars here..
    }
查看更多
放荡不羁爱自由
3楼-- · 2019-01-24 02:50

If you're using apache, consider using a .htaccess file with mod_rewirte. Here a quickstart. I think this result can be obtained on iis as well with web.config file

查看更多
一夜七次
4楼-- · 2019-01-24 02:57

SIMPLE ANSWER

Just place this in the top of the file you need to make the GET querys disappear from the browser's URL bar after loading.

<script>    
    if(typeof window.history.pushState == 'function') {
        window.history.pushState({}, "Hide", '<?php echo $_SERVER['PHP_SELF'];?>');
    }
</script>
查看更多
三岁会撩人
5楼-- · 2019-01-24 03:00

i guess after calling the url you want to redirect to the file ex.php , but this time without any parameters. for that try using the following code in ex.php

<?
if($_GET['name']!='' || $_GET['price']!='' ||$_GET['quantity']!='' ||$_GET['code']!='' || $_GET['search']!=''){ 

/* here the code checks whether the url contains any parameters or not, if yes it will execute parameters stuffs and it will get redirected to the page http://localhost/join/prog/ex.php without any parameters*/

/* do what ever you wish to do, when the parameters are present. */

echo $name;
print $price;
//etc....

$location="http://localhost/join/prog/ex.php";
echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
exit;
}
else{
 /* here rest of the body i.e the codes to be executed after redirecting or without parameters.*/
echo "Hi no parameters present!";
}
?>

here what u did id just redirect redirect to the same page without checking if any parameter is there in the query string. the code intelligently checks for the presence of parameters, id any parameters are there it will redirect to ex.php else it will print "Hi no parameters present!" string!

查看更多
登录 后发表回答