我有以下代码
$timeNow = time();
$timeExpire = $timeNow - 15;
$con->query("UPDATE players SET Time='".$timeNow."', TimeExpire='".$timeExpire."' WHERE Username='". $_SESSION['Username']."'");
$User = $con->query("SELECT * FROM players WHERE Username='".$_SESSION['Username']."'");
$UserInfo = $User->fetch_object();
if($UserInfo->Wood == "") {
$con->query("UPDATE players SET Wood='0'");
} elseif($UserInfo->Stone == "") {
$con->query("UPDATE players SET Stone='0'");
} elseif($UserInfo->Gold == "") {
$con->query("UPDATE players SET Gold='0'");
}
if((time() - 15) >= $UserInfo->TimeExpire) {
$getAmount = (time() - $UserInfo->TimeExpire);
$con->query("UPDATE players SET Wood=Wood+$getAmount, Stone=Stone+$getAmount, Gold=Gold+$getAmount WHERE Username='". $_SESSION['Username']."'");
}
我有一些问题:
我怎样才能让用户每 10 秒只能收到一次木头、石头和金子(否则他们只能刷新页面)
我如何计算有多少到期?例如,如果他们注销 2 小时,然后重新登录,他们会得到与
在线 2 小时一样的钱