php - 如何从 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
我为什么要删除它?好吧,既然人们可以刷新页面,他们可能会滥用某些东西。有哪些方法?
解决方案
使用重定向是您可以尝试的一种选择:
<?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
推荐阅读
- r - 如何使用大数据包读取 R 中的大型 sav 文件
- keyboard-shortcuts - 根据光标附近的字符更改 Atom 键绑定行为
- matlab - 如何在 MATLAB 中绘制具有恒定长度和随机角度的线?
- c# - 如何解析非分隔日期格式?
- android - 在android中将假voip合并到蜂窝电话
- python - 如何删除 QTreeWidget 的 currentItem?
- apache-spark - 使用 Spark saveAsTable +覆盖模式最大限度地减少 Hive 表的停机时间
- deployment - 如何在 ibm 云中部署应用程序(红色节点)
- sql - 如何使用 SSIS 包中的 Foreach 循环容器仅选择 5 个 Excel 文件并加载到 sql 数据库中
- docker - docker-engine 如何处理来自/到多个容器的传出和传入流量?