does this even work?
|
|
go to your website, add this php code:
Change server ip + port to your server ip + port and this will say in green "online" if server online or "offline" if server offline.Code:<?php $ip = "SERVER IP"; //put your ipaddress here $port= "SERVER PORT"; //the port number $online = '<font color="green">Online</font>'; //This can be text or image $offline = '<font color="red">Offline</font>'; //This can be text or image if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) //Checks the server's status { echo "$offline"; //When server status is offline, output this } else { echo "$online"; //Else, output this } ?>


Not even your own work...
[PHP]<?php
$ip = "google.com";
$port= "80";
if (!$sock = @fsockopen($ip, $port, $num, $error, 5))
{
echo "<font color=\"red\">Offline</font>";
} else {
echo "<font color=\"green\">Online</font>";
}
?>[/PHP]
Would do fine, why have $online and $offline?
If you feel like having them, why not use
[PHP]echo $online/PHP]
instead of
[PHP]echo "$online"/PHP]
Sure it does, but by refreshing a lot you could try and crash a RuneScape Private Server even
Most of them have nulling protection now though.
F*ck off; all server socket opens written in PHP are all the same, literally.
Might I suggest you explain the other parameters so they don't have to wait FIVE seconds for a page to load?
$num is the error number you'd get if there was something wrong.
$error is the error message in a string -- basically if the server is offline, it says "The socket you attempted failed because the server is offline", or something similar.
The five indicates the timeout.
If your timeout is set to five, then the page is going to attempt to check the server. If the server is offline, the page will not load for five seconds, because the server socket will continue to check for five seconds before actually sending the whole page to the client.
Therefore... I suggest you set the timeout to a lower value if you don't want the page taking five seconds to load, or... you could do like a pre-load technique, although I haven't worked with that much. If you run the "server" on the same "box" as the webserver, then you should definately set it to a really low value, maybe as low as 0.001 seconds, since a reply for an online status to localhost only takes less than a millisecond.
tl;dr -- USE A LOWER TIMEOUT.
~Z
Zachera knows his php.. and ummm yeah just as MyBGod asked, why put double quotes when echoing a variable
![]()
My server just says offline always. o.O
| « how to start working with Java Script | Basic Arrays ( We create a VERY basic login ) » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |