I wanna place an image on my website that will change depending on server status. So i found this php script that connects to ftp server. but here is what i really want and i don't want it to connect via ftp just standard image get Get onlineimage.gif from downloads.myserver.com if not availabe get offlineimage.gif from downloads.otherserver.com Code (markup): What i found <? $offimg="path_to_offline_image.gif";Â $onimg="path_to_online_image.gif";Â $ftp = fsockopen($HTTP_HOST, 21); if(!$ftp){ $status="<img src=\"$offimg\">"; } else { $status="<img src=\"$onimg\">"; } echo $status; ?> PHP: and can this be done in JS or html Thank you
Well here is the thing: I have a forum that provides high speed download with no speed limits no waiting time, and no ads... so in order to provide such speed and so on i have installed my own server at home... the thing is i need to restart server from time to time and sometimes have it offline for upgrades but i need to have the members on my forum to know before they download so the webserver that is hosting my web forum will have the offline massage and my download server will have the online massage or image
I'd recommend a server-side solution for this (in your case, PHP). <?php $hostname = 'google.com'; $port = 21; $image = array(); $image['online'] = 'online.png'; $image['offline'] = 'offline.png'; $ftp = @fsockopen($hostname, $port); $status = (!$ftp) ? 'online' : 'offline'; // $status will be either online or offline. echo '<img src="'.$image[$status].' />'; PHP: I hope this helps you for what you need. I haven't tested it though, so let me know if any issues rise.
A way you could do it just using HTML/PHP would be: HTML: <img class="status" src="http://downloads.myserver.com/onlineimage.gif?<?=time()?>" alt="" onerror="this.src='http://downloads.anotherserver.com/offlineimage.gif';" /> You need PHP to output the current time (onlineimage.gif?<?=time()?>) because you want to prevent browsers from caching the image. You want a fresh request for the image every time the page is loaded to get an up-to-date status on your server. If your server can't load the image, then the 'onerror' event is called, and we have set it to change the image's source to your offline image. If you don't want to use PHP and want a pure JS/HTML solution, you could do something like this: <script> var time = (new Date()).getTime(); document.write('<img class="status" src="http://downloads.myserver.com/onlineimage.gif?'+time+'" alt="" onerror="this.src=\'http://downloads.anotherserver.com/offlineimage.gif\';" />'); </script> I hope that helps you out. Let me know if something is off or if you hit any obstacles.