Joshua F Posted August 9, 2010 Share Posted August 9, 2010 I am trying to make a Server Status checker that uses a image to tell if it is online or not. I also am trying to make it so you can the URL as a image code(EX: Http://domain.com/statuscheck.php?ip=google.com&port=80). What I'm trying to say it, that if you do like <img src="Http://domain.com/statuscheck.php?ip=google.com&port=80"> it would go to my site, use the php script, and then have the image Online or Offline, were the <img> code was posted. Here's my code Im trying to make it from. <?php $ip="{$_GET['ip']}"; $port="{$_GET['port']}"; if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) { Header('Content-type: image/png'); echo"<img src='images/offline.png'>"; } else { Header('Content-type: image/png'); echo"<img src='images/online.png'>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/ Share on other sites More sharing options...
Alex Posted August 9, 2010 Share Posted August 9, 2010 An HTML <img> tag is not valid image file data. You should use readfile. Like so: <?php $ip="{$_GET['ip']}"; $port="{$_GET['port']}"; header('Content-type: image/png'); if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) { readfile('image/offline.png'); } else { readfile('image/online.png'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/#findComment-1096819 Share on other sites More sharing options...
Joshua F Posted August 9, 2010 Author Share Posted August 9, 2010 An HTML <img> tag is not valid image file data. You should use readfile. Like so: <?php $ip="{$_GET['ip']}"; $port="{$_GET['port']}"; header('Content-type: image/png'); if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) { readfile('image/offline.png'); } else { readfile('image/online.png'); } ?> So lets say I posted a Image BBCode with this in it [img=http://domain.com/statuscheck.php?ip=google.com&port=80] It would put the online/offline image wherever I put that code right? Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/#findComment-1096823 Share on other sites More sharing options...
Alex Posted August 9, 2010 Share Posted August 9, 2010 Try it and find out. Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/#findComment-1096827 Share on other sites More sharing options...
Joshua F Posted August 9, 2010 Author Share Posted August 9, 2010 It works, but would you know how to make it so if the Server is offline, it doesn't take any longer to load. That could cause some problems if someone posted it on something. Online Offline Look how much longer it takes for the Offline image to load. Edit: Also, if this is used a lot, would it eat up Monthly Bandwidth? Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/#findComment-1096839 Share on other sites More sharing options...
jcbones Posted August 9, 2010 Share Posted August 9, 2010 Of course it will take longer for it to load if the server is offline. The fsocketopen() will have to wait for the timeout to expire. Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/#findComment-1096844 Share on other sites More sharing options...
Joshua F Posted August 9, 2010 Author Share Posted August 9, 2010 Of course it will take longer for it to load if the server is offline. The fsocketopen() will have to wait for the timeout to expire. Alright, just checking to see if there was a way to make it load faster. But do you know if it will eat up alot of Bandwidth? Quote Link to comment https://forums.phpfreaks.com/topic/210176-server-status-checker/#findComment-1096847 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.