• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Release]Simple Server Status PHP

Joined
Aug 16, 2006
Messages
1,251
Reaction score
200
Something Omnija asked me to do.

Server uses port 7002

Dont forget to change the ip 127.0.0.1 to your ip if you plan to make your server public.

PHP:
<?php $interval     = time()+120;

error_reporting(0); //without this you will se an error if the server is down.


if($_COOKIE["checked"] != "true")
{
$server = fsockopen("127.0.0.1", "7002", $errno, $errstr, 1);

if(!$server){ $account_status = "Server Status: <b>Offline</b>"; setcookie("server_status", "Offline", $interval); } else { $server_status = "Server Status: <b>Online</b>"; }

setcookie("checked", "true", $interval);
}
else
if($_COOKIE["checked"] == "true")
{
if($_COOKIE["server_status"] == "Offline"){ $server_status = "Server Status: <b>Offline</b>"; } else { $server_status = "Server Status: <b>Online</b>"; }
} ?>



<?php echo "".$server_status; ?>

Sloppy? yes. Do i care? no.
Learn from the code and make it better :]

Online:
-DefaulT - [Release]Simple Server Status PHP - RaGEZONE Forums


Offline:
-DefaulT - [Release]Simple Server Status PHP - RaGEZONE Forums



Enjoy!
 
Last edited:
Newbie Spellweaver
Joined
Dec 17, 2008
Messages
90
Reaction score
1
This one is abit cleaner.

PHP:
function server_status(){
	$fp = @fsockopen("127.0.0.1", "7002", $errno, $errstr, 1); // change "127.0.0.1" to your ip
	if (!$fp){ 
		$status = "offline"; // offline message
	}else{ 
		$status = "online"; // online message
	} @fclose($fp);
	return $status;
}

How to use in page you ask?

PHP:
<?php
	## server check function ##
	function server_status(){
		$fp = @fsockopen("127.0.0.1", "7002", $errno, $errstr, 1); // change "127.0.0.1" to your ip
		if (!$fp){ 
			$status = "offline"; // offline message
		}else{ 
			$status = "online"; // online message
		} @fclose($fp);
		return $status;
	}
	
	## display server check ##
	echo "Server status: " . server_status();
?>

EDIT:
You can style the offline or online message!
Like this:
PHP:
<?php
	## server check function ##
	function server_status(){
		$fp = @fsockopen("127.0.0.1", "7002", $errno, $errstr, 1); // change "127.0.0.1" to your ip
		if (!$fp){ 
			$status = "<font style=\"color: red;\">offline</font>"; // offline message with red text
		}else{ 
			$status = "<font style=\"color: green;\">ONLINE</font>"; // online message with green text and uppercase
		} @fclose($fp);
		return $status;
	}
	
	## display server check ##
	echo "Server status: " . server_status();
?>
 
Last edited:
Initiate Mage
Joined
Aug 4, 2013
Messages
1
Reaction score
0
hey default why do i get error when i register its like unknown error

i dont know if u could help me with register and the login please and please make it as a video it would be better thanks
 
Back
Top