剥离。从文本框的
Stripping . from text box's
您好,我在发帖之前使用了搜索。
我是 php/mysql 的新手,读了很多书。已经能够做出几个朋友都在玩的游戏。它就像一个 pvp 游戏。
不管怎么说,其中一个玩游戏的人找到了一种方法,通过将 .在价值面前。我有去除非法字符的保护功能
function protect($string) {
return mysql_real_escape_string(strip_tags(addslashes($string)));
}
这适用于其他角色,但不适用于 .我不是要别人为我做这件事,只是想指出正确的方向。
但是有人问这里是我使用的代码
if(isset($_POST['buy'])){
$sword = protect($_POST['sword']);
$shield = protect($_POST['shield']);
$gold_needed = (10 * $sword) + (10 * $shield);
if($sword < 0 || $shield < 0){
output("You must buy a positive number of weapons!");
}elseif($stats['gold'] < $gold_needed){
output("You do not have enough gold!");
}else{
$weapon['sword'] += $sword;
$weapon['shield'] += $shield;
$update_weapons = mysql_query("UPDATE `weapon` SET
`sword`='".$weapon['sword']."',
`shield`='".$weapon['shield']."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$stats['gold'] -= $gold_needed;
$update_gold = mysql_query("UPDATE `stats` SET `gold`='".$stats['gold']."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
include("update_stats.php");
output("You have bought weapons!");
}
如果有人能帮助我,我将不胜感激
我确实找到了东西"string functions, substr replace and str replace"
但是我可以在 1 个查询中使用两个函数吗?抱歉我是新人
编辑***
这是在 update_stats
中发布的查询
$update_stats = mysql_query("UPDATE `stats` SET
`income`='".$income."',`farming`='".$farming."',
`attack`='".$attack."',`defense`='".$defense."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
one of the people playing found a way to glitch buying and selling units by putting a . in front of the value
好吧,您还没有透露具体的漏洞是什么,但我敢猜测,通过输入十进制值,他们 运行 围绕您的 pricing/math?那么,我应该考虑多种可能性?
if (substr($string, 0, 1) == ".") {
//return false, warn, etc.
}
那可以在你的 "protect" 函数中。
同样,您可以使用 intval() 甚至 is_numeric() ...在这里我只是将它添加到作业中:
$sword = protect(intval($_POST['sword']));
您也可以使用正则表达式。我假设 $value 是数字?最多多少位数?我用过 5:
if (preg_match("%\.\d{1,5}%", $sword)) { //this guy's playing w/us
die("Go away, bad hax0rz! :-P");
}
您好,我在发帖之前使用了搜索。
我是 php/mysql 的新手,读了很多书。已经能够做出几个朋友都在玩的游戏。它就像一个 pvp 游戏。
不管怎么说,其中一个玩游戏的人找到了一种方法,通过将 .在价值面前。我有去除非法字符的保护功能
function protect($string) {
return mysql_real_escape_string(strip_tags(addslashes($string)));
}
这适用于其他角色,但不适用于 .我不是要别人为我做这件事,只是想指出正确的方向。
但是有人问这里是我使用的代码
if(isset($_POST['buy'])){
$sword = protect($_POST['sword']);
$shield = protect($_POST['shield']);
$gold_needed = (10 * $sword) + (10 * $shield);
if($sword < 0 || $shield < 0){
output("You must buy a positive number of weapons!");
}elseif($stats['gold'] < $gold_needed){
output("You do not have enough gold!");
}else{
$weapon['sword'] += $sword;
$weapon['shield'] += $shield;
$update_weapons = mysql_query("UPDATE `weapon` SET
`sword`='".$weapon['sword']."',
`shield`='".$weapon['shield']."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$stats['gold'] -= $gold_needed;
$update_gold = mysql_query("UPDATE `stats` SET `gold`='".$stats['gold']."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
include("update_stats.php");
output("You have bought weapons!");
}
如果有人能帮助我,我将不胜感激
我确实找到了东西"string functions, substr replace and str replace"
但是我可以在 1 个查询中使用两个函数吗?抱歉我是新人
编辑***
这是在 update_stats
中发布的查询$update_stats = mysql_query("UPDATE `stats` SET
`income`='".$income."',`farming`='".$farming."',
`attack`='".$attack."',`defense`='".$defense."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
one of the people playing found a way to glitch buying and selling units by putting a . in front of the value
好吧,您还没有透露具体的漏洞是什么,但我敢猜测,通过输入十进制值,他们 运行 围绕您的 pricing/math?那么,我应该考虑多种可能性?
if (substr($string, 0, 1) == ".") {
//return false, warn, etc.
}
那可以在你的 "protect" 函数中。
同样,您可以使用 intval() 甚至 is_numeric() ...在这里我只是将它添加到作业中:
$sword = protect(intval($_POST['sword']));
您也可以使用正则表达式。我假设 $value 是数字?最多多少位数?我用过 5:
if (preg_match("%\.\d{1,5}%", $sword)) { //this guy's playing w/us
die("Go away, bad hax0rz! :-P");
}