Jump to content

[SOLVED] HELP: Simple IF THEN ELSE image script


rjsws

Recommended Posts

I am trying to be able to check my server status with images.

I have 4 servers that I need to watch.

 

I was thinking that if I had a list that had the names of the server followed by a little red or green circle depending on the status.

 

Here is the list of servers:

rjsws.com

bbmillc.com

roblaptop.gotdns.com:81

jabbaware.gotdns.com

 

I was thinking if I could point at an image/document on the server that it the script run the "then" part, if not then it would run the "else".

It seems to work locally but not anywhere else.

 

<?
error_reporting(0);
$url="http://jabbaware.gotdns.com/rob/status/j.png";
$file = file_get_contents( $url );
if ($file)
{
echo 'Up<img src="http://rjsws.110mb.com/up.png">';
}
else
{
echo 'Down<img src="http://rjsws.110mb.com/down.png">';
}
?>

 

I'm going crazy here...  Please help me figure out how to do this!

 

-Rilla

I'm not too sure, but try:

 

<?php
error_reporting(0);
$url="http://jabbaware.gotdns.com/rob/status/j.png";
$file = file_get_contents( $url );
if ($file > 0)
{
echo 'Up<img src="http://rjsws.110mb.com/up.png">';
}
else
{
echo 'Down<img src="http://rjsws.110mb.com/down.png">';
}
?>

conker87 - Thanks for the reply.

 

The code still isn't working.  It seems like such an easy thing to do.  I just can't figure it out!

 

Well...  It sorta works.  It displays "Down" and the red dot.

 

I don't know what I should do next.

 

Someone please help :(

 

-Rilla

You could also try:

<?php
error_reporting(0);
$url="http://jabbaware.gotdns.com/rob/status/j.png";
$file = file_exists($url);
if ($file)
{
echo 'Up<img src="http://rjsws.110mb.com/up.png">';
}
else
{
echo 'Down<img src="http://rjsws.110mb.com/down.png">';
}
?>

 

This might work, if your site is down, then technically the file doesn't exist, right?

It still doesnt work.

I am totally baffled with this.

Originally I was just going to do a simple page showing image files from each of the servers, so if the server was down then the image wont show.

 

Are there any other code ideas to try?  A different approch to showing one image is the server is down and a different if it's up?

 

I'm sure there's a way to check to see if a domain is vaild e.g. rjsws.com and if it is show a image, if it's not then show another image.

 

Ahhh...  I'm going crazy!

 

 

http://rjsws.110mb.com/status.php

Perhaps just:

 

<?php
error_reporting(0);
$url="http://jabbaware.gotdns.com/rob/status/j.png";
if (file_exists($url))
{
echo 'Up<img src="http://rjsws.110mb.com/up.png">';
}
else
{
echo 'Down<img src="http://rjsws.110mb.com/down.png">';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.