我有一个csgo博彩网站,当至少有2名玩家将皮肤存入该网站时,游戏开始,机器人需要2分钟才能选出赢家。
一切正常,游戏开始,在游戏开始2分钟后选出获胜者,但本应显示剩余秒数的倒计时文本不起作用。
这是我的代码Time left: <h4 id="countdown-timer"><span id="timeleft">0</span></h4>
XXXXXXX(XXXXXXXXXXXXX)接受的交易报价编号1211760373当前玩家:1XXXXXXXXXX(XXXXXXXXXXXXXXXX)接受的交易报价编号1211760308当前玩家:2找到2名玩家
机器人就是这么说的
这是timeleft.phphttp://prnt.sc/b03ute
PHP代码
<?php
@include_once ("set.php");
$game = fetchinfo("value", "info", "name", "current_game");
$r = fetchinfo("starttime", "games", "id", $game);
$somebodywon = fetchinfo("winner", "games", "id", $game);
if ($r == 2147483647)
die("120");
$r += 120 - time();
if ($r < 0) {
$r = 0; /* if(empty($somebodywon)) include_once('getwinner34634f.php'); */
} echo $r;
?>
也找到了这个,叫做ssetimeleft.php
<
?php
@include_once ("set.php");
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.
/**
* Constructs the SSE data format and flushes that data to the client.
*
* @param string $id Timestamp/id of this connection.
* @param string $msg Line of text that should be transmitted.
*/
function sendMsg($id, $msg) {
echo "id: $id" . PHP_EOL;
echo "data: $msg" . PHP_EOL;
echo PHP_EOL;
ob_flush();
flush();
}
while (1) {
$game = fetchinfo("value","info","name","current_game");
$r = fetchinfo("starttime","games","id",$game);
if($r == 2147483647){
$var=120;
}else{
$var = $r += 120-time();
if($r < 0)
{
$var = 0;
/*if(empty($somebodywon))
include_once('getwinner34634f.php');*/
}
}
sendMsg(time(),$var);
usleep(500000); //1000000 = 1 seconds
}
?>
如果没有更多信息,很难看到您在这里试图做什么,但PHP文件中的time()
函数只有在服务器端PHP处理器处理该文件时才会运行。然而,倒计时显示应该在客户端处理。
我建议添加一个javascript或jQuery文件来处理倒计时显示。
试试这是一个非常基本的例子:
$(function() {
var time_out = 10;
var timeout = setInterval(calculate, 1000);
function calculate() {
$('#timeleft').text(time_out--);
if (time_out < 0) {
clearInterval(timeout);
}
}
});
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<h4 id="countdown-timer"><span id="timeleft">0</span></h4>
</body>
</html>