What I have here is a PHP script that pings a domain and prints out its status either Online or Offline depending if the ping is successful or not. I want it to do exactly what it does but instead of it printing the words Online or Offline I would like it to display an icon image I have of the Online and Offline status. If anyone could help me out and explain to me how to go about doing this I would be indebt to you forsure. There are 3 parts to this script an Index.php, a ping.php and a style.css below is the code for each. Image of what it looks like Index.php <? ?> <html> <head> <LINK REL=stylesheet TYPE="text/css" HREF="style.css"> </head> <body> <? include_once("ping.php"); echo " <table><tr><td class=border> <a href=http://www.domainname.com>Domain Name</a> </td><td class=border>"; chkuri("www.domainname.com",1); echo "</td></tr> </table>"; ?> </body> </html> Ping.php <? function chkuri($link, $option) { if(substr($link,0,4)!="http"){ $link = "http://".$link; } $timestart = microtime(); $churl = @fopen($link,'r'); $timeend = microtime(); $diff = number_format(((substr($timeend,0,9)) + (substr($timeend,-10)) - (substr($timestart,0,9)) - (substr($timestart,-10))),4); $diff = $diff*100; if (!$churl) { $message="<center><b><div class=offline>Offline</div></center></b>"; }else{ $message="<center><b><div class=online>Online</div></b></center> "; if($option==1){ $message = $message."[ ping: ".$diff."ms ]";} } echo $message; } ?> Style.css a.link { color: green; font-size: 11px; text-decoration: none;} td.border {font-size: 12px; border: #449944 solid 2px;} .offline { color: red; } .online { color: Green; } Thanks to anyone that can help. Flawless1974
Well just a quick look through, but you should just be able to change the following code: $message="<center><b><div class=offline>Offline</div></center></b>"; }else{ $message="<center><b><div class=online>Online</div></b></center> "; if($option==1){ $message = PHP: To be your images instead. So something like this: $message="<center><b><div class=offline><img src="offline.gif" alt="Offline" /></div></center></b>"; }else{ $message="<center><b><div class=online><img src="online.gif" alt="Online" /></div></b></center> "; if($option==1){ $message = PHP: Hope that is some help.
See thats what I thought it would be but this is the error I keep getting when going to the webpage. Parse error: parse error in C:\Inetpub\vhosts\emagine-hosting.com\httpdocs\ping\ping.php on line 20 which line 20 is the line I put the img into. So this is what I have in my ping.php file. <? function chkuri($link, $option) { if(substr($link,0,4)!="http"){ $link = "http://".$link; } $timestart = microtime(); $churl = @fopen($link,'r'); $timeend = microtime(); $diff = number_format(((substr($timeend,0,9)) + (substr($timeend,-10)) - (substr($timestart,0,9)) - (substr($timestart,-10))),4); $diff = $diff*100; if (!$churl) { $message="<center><b><div class=offline><img src="/offline.png"></div></center></b>"; }else{ $message="<center><b><div class=online><img src="/online.png"></div></b></center> "; if($option==1){ $message = $message."[ ping: ".$diff."ms ]";} } echo $message; } ?> Flawless1974
Oh, it is getting late, I missed the quotes. You need to escape the quotes in the image tag. So <img src="/offline.png"> becomes <img src=\"/offline.png\">.
Just use the If statement and if the Online is found then put tag for online image else offline image.