What's new

The easiest server on/offline status tutorial for your uber epic website!

Adriel

Verified Member
27
2014
6
Location
Las Vegas, Nevada, USA
There are several server status sniffers out there but it seems many of the creators fail to give you a simple application tutorial such as how to get the damn thing working..

the code below should be (should be being the key words here) pretty self teaching. I placed footnotes alongside each line to try and explain what each line is doing or is for, etc.

Forgive me if it's not ITT perfect, I am no teacher by any means but I figured I would try to give some new people to web development and coding a simple example that WORKS without a huge mass of headache and 20 million questions..

This code is for one (1, Uno, A Single) server to be detected. if you want to detect more then you will have add things like $host2, $port2, etc and improvise.. Just study the code and feel free to experiment with it and adding more servers or whatever.

Above all DO NOT let PHP intimidate you. Once you get the hang of it, it's really not that trivial to work with and your web server will thank you.

Code:
<?php // opens a php tag

$host1 = "elfnet-designs.com";  // Sets the servers IP Address, Hostname or URL

$port1 = "80";  // Sets the servers port you want to detect

if (! $sock = @fsockopen($host1, $port1, $num, $error, 3)) // If statement opens a $sock for host1 at port1 (you set above) and has a 3 second detect timer.

echo '<B>Web Server is: <FONT COLOR=red>OFFLINE</b></FONT>';   //This echos ONLINE in green on the webpage IF the server is detected online. 

else{ //Else = If no server is detected online then throw the next echo below...

echo '<B>Web Server is: <FONT COLOR=lime>ONLINE</b></FONT>';  //And so we didn't detect a serve online, thus we see OFFLINE in red on the webpage.

fclose($sock);}  // fclose = Force Close the $sock connection and stop sniffing until page refresh


?> <!-- Close up the PHP tag  -->

echo '<B>Web Server is: <FONT COLOR=green>ONLINE</b></FONT>';
and
echo '<B>Web Server is: <FONT COLOR=red>OFFLINE</b></FONT>';

can be modified to show an image instead of text
Code:
echo '<B>Web Server is: <img src=onlineimage.gif>';
else{
echo '<B>Web Server is: <img src=offlineimage.gif>';

Now that you have this script set up and adjusted to your liking its time to implement or deploy it to your website..
There are a few was to do this and the easiest was it to take this script and create a file calles "status.php" and put it in your htdocs folder and create a link to it.

But lets say your using a CMS we'll use wordpress for this example.
What you want to so is deploy this script into the CMS as a widget BUT WAIT! wordpress does not allow PHP in their default text box widget what now? Ok calm down this is an easy fix where you obtain a text box widget addon that supports php code.
You would put this script code into that new addon and plant it on your site and tada. server status should be there wherever you put the widget on the site that is...

Ok not all CMS's are user friendly in adding custom scripts, modules, widgets, etc. So you will have to do your own homework on your CMS to figure out how to deplow a custom php script.

Back to a normal non cms website you can also deploy this script in its own <div>, in a <table>, or call it up from status.php in an <iframe> (inline frame).
There are numerous ways to put this thing up and you just have to find a way that suites you.
 
Last edited:
Top