Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 362
dtnder Avatar asked Dec 09 '12 16:12

dtnder


People also ask

What is get parameter in URL?

GET parameters (also called URL parameters or query strings) are used when a client, such as a browser, requests a particular resource from a web server using the HTTP protocol. These parameters are usually name-value pairs, separated by an equals sign = . They can be used for a variety of things, as explained below.

What does$_ GET mean in PHP?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters: <html> <body>


Video Answer


1 Answers

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..
    }
like image 98
Sanne Avatar answered Oct 07 '22 17:10

Sanne