首页 > 解决方案 > 如何从 URL PHP 中删除 GET 变量?

问题描述

调用后如何从 URL 中删除 GET 变量?

打电话给

<a href="?reward">

在它调用之后

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

正如你所理解的,在我的网址中,我看到了somelink.php?reward

我为什么要删除它?好吧,既然人们可以刷新页面,他们可能会滥用某些东西。有哪些方法?

标签: phphtml

解决方案


使用重定向是您可以尝试的一种选择:

<?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

推荐阅读