How to remove GET variables from URL PHP?

php remove parameter from url
remove get parameters from url javascript
php get current url
laravel remove query string from url
remove one parameter from query string
how to remove url in php
php get value from url
how to remove query string from url in codeigniter

How could i remove GET variable from URL after its called ?

Calling with

<a href="?reward">

After its called

if (isset($_GET['reward'])){

$username = $_SESSION['username'];
$points = $_SESSION['points'];

if ($points >=500) {
  echo " test value is more than 500";
} // ANTRA IF UZDAROM
else {
  echo '<script type="text/javascript">';
  echo 'setTimeout(function () { swal({type: "error",title: "Oops...",text: "You do not have enough points!",buttonsStyling: false,heightAuto: false});';
  echo '}, 1000);</script>';
}   
} // PIRMA IF UZDAROM

And in my url as you understand i see somelink.php?reward

Why would i want to remove it ? Well, since people can refresh page they could abuse something. What are the ways ?

Use redirect is one option you can try:

<?php

session_start();

$_SESSION['username'] = 'User'; //test 
$_SESSION['points'] = 300; //test

if (isset($_GET['reward'])){
   $_SESSION['reward_hit'] = true;
   header('Location: /temp/test.php'); //redirect to same url

} elseif (isset($_SESSION['reward_hit'])) {

    unset($_SESSION['reward_hit']);
    $username = $_SESSION['username'];
    $points = $_SESSION['points'];

    if ($points >=500) {
      echo " test value is more than 500";
    } // ANTRA IF UZDAROM
    else {
      echo " test value is less than 500";  //test
      echo '<script type="text/javascript">';
      echo 'setTimeout(function () { swal({type: "error",title: "Oops...",text: "You do not have enough points!
",buttonsStyling: false,heightAuto: false});';
      echo '}, 1000);</script>';
    }
} // PIRMA IF UZDARO

Beautiful way to remove GET-variables with PHP?, Instead of hacking around with regular expression you should parse the string as an url (what it is) @Brad: I use the GET method to save data to the database. every time I refresh (F5) then the data will continue to enter into the database, because the parameters are still there. so, I want every time after entering parameter data must be erased so that every time I refresh (F5), the data will not be entered into the database because there is no parameter in the url – dtnder Dec 10 '12 at 7:56

For future readers:

Put this code in top of your page

<script>    
    if(typeof window.history.pushState == 'function') {
        window.history.pushState({}, "Hide", '<?php echo $_SERVER['PHP_SELF'];?>');
    }
</script>

*ANSWERED

Function to remove GET variable with php, Recently I needed a function to remove a single query parameter from a given URL in PHP. This seems like the type of thing that there should  Parse the url into an array with parse_url() Extract the query portion, decompose that into an array using parse_str() Delete the query parameters you want by unset() them from the array. Rebuild the original url using http_build_query()

Add to echo of JS code one line:

  echo '<script type="text/javascript">';
  echo 'history.pushState(null, null, url);';
  echo '</script>';

Where url is full domain name of your site.

remove GET parameter in URL after processing is finished(not using , Hi, I have the following form: <form action="/form.php" method="get"> <input type​="text" name="term"> <input type="submit" name="search"  ALL inputs will be shown in the url if you use GET , NONE if you use post. The TRUE reason to use use GET is to make the URL bookmarkable.

Stripping A Query Parameter From A URL in PHP, $_GET -- $HTTP_GET_VARS [deprecated] — HTTP GET variables. Description ¶​. An associative array of variables passed to the current script via the URL method that has a query component in the URI: GET, POST, PUT, PATCH, DELETE. URL's are a nightmare to process. Even though, in your case, it appears that you can use regex to isolate your specific problem, I would still recommend that you avoid regex for URL manipulation. PHP has native URL parsing methods (much better tested and controlled than your code), and you should use them where possible.

Remove a parameter from URL after form submit (GET) - PHP, Parses encoded_string as if it were the query string passed via a URL and sets if you'd like to get rid of the [annoying] plus '+' converted to space ' ' translation. When you work with PHP, you often need to pass variables from one page to another. This lesson is about passing variables in a URL. Maybe you have wondered why some URLs look something like this: Why is there a question mark after the page name? The answer is that the characters after the question mark are an HTTP query string.

PHP: $_GET, Use preg_replace() with REGEX to remove specific query string variable from URL in PHP. Example code to remove specific parameter and its  Submitting form values through GET method. A web form when the method is set to GET method, it submits the values through URL. So we can use one form to generate an URL with variables and data by taking inputs from the users. The form will send the data to a page within the site or outside the site by formatting a query string.

Comments
  • If one can "earn" such a reward by simply making a http request, then you have other issues in your logic than just "removing the GET variable"...
  • If there is a way to abuse it then your concept is not as good as it must be. Fix the concept.
  • They are not earning rewards here, they are "claiming", no, they can't abuse points "value" since its refreshed on every page load. The code isn't finished yet, just thinking about what could happen.
  • I always handle the post request and than refresh using the header() command to a page which they can refresh (a success page, or to the same page without the get info).
  • Possible duplicate of How to make a redirect in PHP?