我的倒计时并没有从我的投注站点开始

时间:2016-05-04 10:43:50

标签: php mysql node.js steam

我有一个csgo投注网站,当至少有2名玩家将他们的皮肤存入网站时,游戏开始,直到机器人选择获胜者需要2分钟。

一切正常,比赛开始,比赛开始后2分钟选出一名获胜者,但应该显示剩余秒数的倒计时文本无效。

这是我的代码Time left: <h4 id="countdown-timer"><span id="timeleft">0</span></h4>

  

XXXXXXX(XXXXXXXXXXXXXX)接受的贸易报价#1211760373   现任球员:1   XXXXXXXXX(XXXXXXXXXXXXXXX)接受的贸易报价#1211760308   现任球员:2   找到2位玩家

这就是机器人所说的

这是timeleft.php http://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

}
?>

2 个答案:

答案 0 :(得分:0)

如果没有更多信息,很难看到您在这里尝试做什么,但PHP文件中的time()函数仅在服务器端PHP处理器处理此文件时运行。但是,倒计时显示应该在客户端处理。

我建议添加一个javascript或jQuery文件来处理倒计时显示。

答案 1 :(得分:0)

尝试这是一个非常基本的例子:

$(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>

相关问题