我一直在为我的在线游戏服务器编写一个脚本,从数据库中获取用户名并检查其级别。
问题是代码不检查级别,因此任何级别的任何人都可以投票并滥用我的投票系统。
注意:该投票系统基于时间/日期,因此您只能每 12 小时投票一次。
表格代码:
<html>
<body>
<center>
Please Enter Your Character Name Below, <br /><br />
After You Vote Please Relogin And Your Cps Will be Added<br /><br />
<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Character Name: <br /><br /> <input type="text" name='CharName'><br>
<br />
<input type="submit" name="button" value="Vote">
</form>
</center>
</body>
</html>
投票代码:
<html><center>
<?php
$user = 'test'; //dbuser
$pass = 'test'; //dbpass
$host = 'localhost'; //dbhost
$name = 'zf'; //dbname
$con = mysql_connect($host, $user, $pass);
mysql_select_db($name, $con);
$datetime = date('Y-m-d');
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_POST['button']))
{
$result1 = mysql_query("SELECT `level` FROM `cq_user` WHERE `name` = '$char_name'") or die(mysql_error());
while($row = mysql_fetch_array($result1))
{
}
error_reporting(E_ALL);
ini_set('display_errors', '1');
$char_name = $_POST['CharName'];
$result = mysql_query("SELECT name FROM cq_user WHERE name = '" . $char_name . "' AND UNIX_TIMESTAMP(lastvoted) <= UNIX_TIMESTAMP('" . date('Y-m-d H:i:s', strtotime('-12 Hours')) . "')") or die(mysql_error());
$result1 = mysql_query("SELECT `level` FROM `cq_user` WHERE `name` = '" . $char_name. "'") or die(mysql_error());
while($row = mysql_fetch_array($result1))
{
}
if (mysql_num_rows($result) == 0 && $row <= 119)
echo "This character does not exist, or you have entered the wrong name. Or you could be trying to cheat and have already voted. Or you are not level 120+.";
else
{
mysql_query("UPDATE `cq_user` SET `emoney` = `emoney` + 100000, `lastvoted`='" . date('Y-m-d H:i:s') . "' WHERE `name` = '" . $char_name . "'") or die(mysql_error());
mysql_query("UPDATE `cq_user` SET `ip` = '$ip' WHERE `name` = '$char_name'");
?>
<meta http-equiv="REFRESH" content="0;url=http://www.xtremetop100.com/in.php?site=1132303596"></HEAD>
<?php
}
}
?>
</html></center>
那是我的检查器
if (mysql_num_rows($result) == 0 && $row <= 119)
这就是我的级别检查器应该工作的部分 <= 119!