来自php的奇怪行为 - 时间倒计时脚本

时间:2016-04-28 18:12:40

标签: php mysqli

我正在一个网站上工作,其中有一些文件是给我的,而且我在找到这种奇怪行为的原因时有点迷失。

以下是发生的事情:

enter image description here

时间应该为0并停止,但它没有。

我不确定我应该把哪些文件/代码放在哪里,因为我不知道造成这个问题的原因。我包括我认为可能包含错误代码的代码(因为我相信它们是"最明显的")但我很乐意在需要时发布更多内容。

timeleft.php

 <?php
    @include_once("set.php");
    $game = fetchinfo("value", "info", "name", "current_game");
    $r    = fetchinfo("starttime", "games", "id", $game);
    if($r == 2147483647)
                    die("30");
    $r += 30 - time();
    if($r < 0)
                    $r = 0;
    echo $r;
?>

set.php

    <?php
$sitename = "localhost";
$link = mysqli_connect("localhost", "root", "");
$db_selected = mysqli_select_db($link, 'website');
mysqli_query($link, "SET NAMES utf8");

function fetchinfo($rowname,$tablename,$finder,$findervalue) {
    if($finder == "1") {
        $result = mysqli_query($GLOBALS['link'], "SELECT $rowname FROM $tablename");
    } else { 
        $result = mysqli_query($GLOBALS['link'], "SELECT $rowname FROM $tablename WHERE `$finder`='$findervalue'") or die (mysqli_error());
    }
    $row = mysqli_fetch_assoc($result);
    return $row[$rowname];
}
?>

当倒数时间变为0时,它应该吸引胜利者,这是 getwinner.php

        <?php
    $mov = "0." . mt_rand(100000000, 999999999);
    @include_once('set.php');
    @include_once('steamauth/steamauth.php');
    @include_once "langdoc.php";
    $cg = fetchinfo("value", "info", "name", "current_game");
    mysqlii_query($link, "UPDATE games SET `module`='$mov' WHERE `id`='$cg'");
    $rs          = mysqli_query($link, "SELECT * FROM games WHERE `id`='$cg'");
    $row         = mysqli_fetch_array($rs);
    $jackpotcost = $row["cost"];
    $jackpot1    = round($jackpotcost, 2);
    $wincost     = $row["cost"] * $mov;
    $rs          = mysqli_query($link, "SELECT * FROM `game$cg` WHERE `from` <= '$wincost' AND `to` >= '$wincost'");
    $row         = mysqli_fetch_array($rs);
    $test        = fetchinfo("userid", "games", "id", $cg);
    if(strlen($test) > 5)
                    $winuser = $test;
    else
                    $winuser = $row["userid"];
    $winname    = fetchinfo("name", "users", "steamid", $winuser);
    $rs         = mysqli_query($link, "SELECT SUM(value) AS ValueSum FROM `game$cg` WHERE `userid`='$winuser'");
    $row        = mysqli_fetch_array($rs);
    $wonpercent = 100 * $row["ValueSum"] / $jackpotcost;
    mysqli_query("UPDATE games SET `percent`='$wonpercent', `winner`='$winname', `userid`='$winuser' WHERE `id`='$cg'");
    $rs = mysqli_query($link, "SELECT userid FROM `game$cg` GROUP BY userid");
    while($row = mysqli_fetch_array($rs)) {
                    if($row["userid"] == $winuser) {
                                    mysqli_query($link, "INSERT INTO `messages` (`id`,`userid`,`msg`,`from`) VALUES ('','$winuser','won','SYSTEM')");
                                    mysqli_query($link, "INSERT INTO `messages` (`id`,`userid`,`msg`,`from`) VALUES ('','$winuser','Вы выиграли $jackpot1$, с шансом $wonpercent%','Победа')");
                    } //$row["userid"] == $winuser
                    else {
                                    $tc = $row["userid"];
                                    mysqli_query($link, "INSERT INTO `messages` (`id`,`userid`,`msg`,`from`) VALUES ('','$tc','lost','SYSTEM')");
                                    mysqli_query($link, "INSERT INTO `messages` (`id`,`userid`,`msg`,`from`) VALUES ('','$tc','$winname выиграл $jackpot1$, с шансом $wonpercent%','Проигрыш')");
                    }
    } //$row = mysqli_fetch_array($rs)
    $rs  = mysqli_query($link, "SELECT item,value FROM `game$cg`");
    $ila = 0;
    while($row = mysqli_fetch_array($rs)) {
                    $itemsar[$ila] = $row["item"];
                    $valuear[$ila] = $row["value"];
                    $ila++;
    } //$row = mysqli_fetch_array($rs)
    for($j = 0; $j < $ila - 1; $j++) {
                    for($i = 0; $i < $ila - $j - 1; $i++) {
                                    if($valuear[$i] > $valuear[$i + 1]) {
                                                    $b               = $valuear[$i];
                                                    $valuear[$i]     = $valuear[$i + 1];
                                                    $valuear[$i + 1] = $b;
                                                    $cc              = $itemsar[$i];
                                                    $itemsar[$i]     = $itemsar[$i + 1];
                                                    $itemsar[$i + 1] = $cc;
                                    } //$valuear[$i] > $valuear[$i + 1]
                    } //$i = 0; $i < $ila - $j - 1; $i++
    } //$j = 0; $j < $ila - 1; $j++
    mysqli_query($link, "UPDATE users SET `won`=`won`+'$jackpotcost', `games`=`games`+1 WHERE `steamid`='$winuser'");
    $rake = fetchinfo("value", "info", "name", "rake");
    $rake += $rake * 0.33;
    if(stristr($winname, "SITENAME") != NULL) {
                    $rake -= 5 / 100;
    } //stristr($winname, "SITENAME") != NULL
    $rake /= 100;
    $rake *= $jackpotcost;
    for($i = $ila - 1; $i >= 0; $i--) {
                    if($valuear[$i] < $rake) {
                                    mysqli_query($link, "INSERT INTO `rakeitems` (`item`) VALUES ('" . $itemsar[$i] . "')");
                                    $itemsar[$i] = "";
                                    $rake -= $valuear[$i];
                    } //$valuear[$i] < $rake
    } //$i = $ila - 1; $i >= 0; $i--
    $boolv = false;
    for($i = 0; $i < $ila; $i++) {
                    if($itemsar[$i] == "")
                                    continue;
                    if($boolv == false)
                                    $itemstring = $itemsar[$i];
                    else
                                    $itemstring .= "/" . $itemsar[$i];
                    $boolv = true;
    } //$i = 0; $i < $ila; $i++
    $rs        = mysqli_query($link, "SELECT * FROM users WHERE `steamid`='$winuser'");
    $row       = mysqli_fetch_array($rs);
    $tradelink = $row["tlink"];
    $token     = substr(strstr($tradelink, 'token='), 6);
    mysqli_query($link, "INSERT INTO `queue` (`userid`,`status`,`token`,`items`) VALUES ('$winuser','active','$token','$itemstring')");
    echo $token . "<br/>";
    echo $itemstring . "<br/>";
    echo mysqli_error() . "<br/>";
    $cg++;
    mysqli_query($link, "INSERT INTO `games` (`id`,`starttime`,`cost`,`winner`,`userid`,`percent`,`itemsnum`,`module`) VALUES ('$cg','2147485547','0','','',NULL,'0','')");
    mysqli_query($link, "CREATE TABLE `game$cg` (
      `id` int(11) NOT NULL auto_increment,
      `userid` varchar(70) NOT NULL,
      `username` varchar(70) NOT NULL,
      `item` text,
      `color` text,
      `value` text,
      `avatar` varchar(512) NOT NULL,
      `image` text NOT NULL,
      `from` text NOT NULL,
      `to` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;");
    mysqli_query($link, "TRUNCATE TABLE `game$cg`");
    mysqli_query($link, "UPDATE info SET `value`='$cg' WHERE `name`='current_game'");
    mysqli_query($link, "UPDATE info SET `value`='waiting' WHERE `name`='state'");
?>

0 个答案:

没有答案