Hi there!
I have created a script which allows users to check to see if their server is online. Obviously running this script from the same server and trying to check your server status whilst its down its too clever, so try using an include or iframe from a free hosting company.
Ok, I will be checking my website, jamesterror.net on port 80 which is the HTTP port.
Firstly you'll need to setup your variables.
| <?php
$site = 'jamesterror.net'; $port = '80'; |
This is setting up the site you will be checking and on the port you will be checking.
| $check = fsockopen( "$site", "$port", $errno, $errstr, 6 ); |
This t string $check is now making a connection to a website by using the 'fsockopen' command.
Now we are going to add the part where it say if the server is offline. I have decided to put it in red font so it stands out.
| if ( ! $check ){ echo "<font color="#FF0000">Server is Currently Down!</font>"; |
What this has now done is, if $check (connection to the site) is unable to connect it was echo the message "Server is Currently Down".
We then add the final lines,
| }
else{ echo "<font color="#009900">Everything is fine!</font>";} |
We now use the ELSE statement, this is so if there is a connection the page will show "Everything is fine!"
Here is the complete script
| <?php
$site = 'jamesterror.net'; $port = '80'; $check = fsockopen( "$site", "$port", $errno, $errstr, 6 ); if ( ! $check ){ echo "<font color="#FF0000">Server is Currently Down!</font>"; } else{ echo "<font color="#009900">Everything is fine!</font>";} ?> |
Thank you, James

Jonessie July 05, 2007 says:Um, one does apologise for being a pain in the butt, I found an error in your code, nothing serious just when you are using tables or fonts you cannot use "" the same as the script. example ""; this will produce an error. Whilst using ''; will be fine. I tinckered with your code a little, because it was a little cluttered.
| : |
| <?php $site = 'yourwebsite.com'; $port = '80'; $check = fsockopen("$site", "$port", $errno, $errstr, 6); if (!$check) { echo '<font color="#FFF0000">Server is currently down!</font>'; } else { echo '<font color="#009900">Everything is fine</font>'; } ?> |





