WoW server uptime script in PHP using PDO for TrinityCore.
It's custom, simple and secure.
<?php
// WoW server uptime and max. players
$query_uptime_wotlk = "SELECT starttime, maxplayers FROM uptime WHERE realmid = '1' ORDER BY starttime DESC LIMIT 1";
$query_con_uptime_wotlk = $conn -> prepare($query_uptime_wotlk);
$query_con_uptime_wotlk->execute();
$res_uptime_wotlk = $query_con_uptime_wotlk->fetch(PDO::FETCH_ASSOC);
$uptimetime = time() - $res_uptime_wotlk['starttime'];
function format_uptime($seconds) {
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
$uptimeString='';
if ($days) {
$uptimeString .= $days;
$uptimeString .= ((1 === $days) ? ' day' : ' days');
}
if ($hours) {
$uptimeString .= ((0 < $days) ? ', ' : '').$hours;
$uptimeString .= ((1 === $hours) ? ' hour' : ' hours');
}
if ($mins) {
$uptimeString .= ((0 < $days || 0 < $hours) ? ', ' : '').$mins;
$uptimeString .= ((1 === $mins) ? ' minute' : ' minutes');
}
if ($secs) {
$uptimeString .= ((0 < $days || 0 < $hours || 0 < $mins) ? ', ' : '').$secs;
$uptimeString .= ((1 === $secs) ? ' second' : ' seconds');
}
return $uptimeString;
}
$staticUptime = format_uptime($uptimetime);
unset($uptimetime);
echo "
<div>
<span style=\"font-size:0.8em;color:#B0BEC5;\">Uptime: ".$staticUptime."</span><br />
<span style=\"font-size:0.8em;color:#B0BEC5;\">Max. players: ".$res_uptime_wotlk[maxplayers]."</span>
</div>";
unset($staticUptime);
unset($query_con_uptime_wotlk);
?>
Info! ' is single quote (')
You can customize the
echo "" results according to your needs.
PDO is inherently secure.
--