<?php
function GetUptime()
{
$file = "MANGOS_LOCATION\MangoScript\misc\uptime.dat"; // Change the uptime.dat path !
if (file_exists ($file)) {
$contents = file($file);
$result = array();
eval('$result'.$contents[2]);
$now = 1440 * (intval(date("z") - 1)) + (60 * intval(date("H"))) + intval(date("i")); // intval(date("z") - 1) -1 because we do not need calculated current day because it's not passed yet.
$up = explode(":", $result["time"]);
$up = 1440 * (intval($up[0] - 2)) + (60 * intval($up[1])) + intval($up[2]); // intval($up[0] - 2) -2 because mangoscript stores the number of the day in a range from 1 to 366 and we do not need calculated current day because it's not passed yet.
} else { $up = 0; $now = $up; }
$fp = @fsockopen('127.0.0.1', 8085, $errno, $errstr, 2); // Change port 8085 if you use other
if($fp){
if(($now > $up) || (($now-$up) == 0)) {
$uptime = $now-$up;
} else {
$uptime = (525600 - $up) + $now; // Do not change 525600. It will mess up the script.
}
$days = floor($uptime/1440);
$hours = floor($uptime/60) - ($days * 24);
$minutes = $uptime - ($hours * 60) - ($days * 1440);
return $days."d ".$hours."h ".$minutes."min";
} else {
return "Offline"; // Change text Offline if you want.
}
}
$uptime = GetUptime();
?>