出于某种原因,当用户注册时,他们不是从 0 Wood、0 Stone、0 Gold 开始,而是以时间戳作为他们的 Wood、Stone 和 Gold(数字,如 1375674873)开始。我的错误在哪里?
$timeNow = time();
$timeExpire = $timeNow - 2;
$User = $con->query("SELECT * FROM players WHERE Username='".$_SESSION['Username']."'");
$UserInfo = $User->fetch_object();
$con->query("UPDATE players SET Time='$timeNow' WHERE Username='". $_SESSION['Username']."'");
$con->query("UPDATE players SET TimeExpire='$timeExpire' WHERE Username='". $_SESSION['Username']."'");
if(time() >= $UserInfo->TimeExpire) {
$getAmount = time() - $UserInfo->TimeExpire;
echo $getAmount;
$con->query("UPDATE players SET Wood=Wood+$getAmount WHERE Username='". $_SESSION['Username']."'");
$con->query("UPDATE players SET Stone=Stone+$getAmount WHERE Username='". $_SESSION['Username']."'");
$con->query("UPDATE players SET Gold=Gold+$getAmount WHERE Username='". $_SESSION['Username']."'");
}
使用$getAmount我正在计算有多少到期。因此,即使用户已注销,当他们在 2 小时后重新登录时,他们仍然可以获得那段时间的钱。