Search code examples
phphtmlurlget

remove GET parameter in URL after processing is finished(not using POST), PHP


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?


Solution

  • 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;

    <?php
        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..
        }