?ping ip and graphic shows one or the other on results?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Minni
Forum Newbie
Posts: 3
Joined: Mon Nov 10, 2003 3:48 pm

?ping ip and graphic shows one or the other on results?

Post by Minni »

I have a friend who asked this question below and I am unable to answer so I am searching for someone who can. Can anyone answer this question?

I am looking for the code that allows you to ping an ip and port and when the ip and port are active then it shows a graphic and when it is not it shows a different graphic. I have tried a few things and have managed to make a pinger but i dont know how to integrate the graphic stuff
here is the pinger i made

Code: Select all

$command = "ping -c1 123.456.789:123456"; 
system($command);
Thank you ;-)
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<?php
$command = "ping -c1 123.456.789:123456"; 
$img = "path/to/image";
if(system($command))
{
$img = "path/to/differnet/image";
}  
echo "<img src="$img">";
?>
i never have worked with system but try this.
Minni
Forum Newbie
Posts: 3
Joined: Mon Nov 10, 2003 3:48 pm

Post by Minni »

Thanks a bunches sweety, I'll see if this helps my friend ;-)

Smooches,
Minni
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

you better be a girl LOL cos i dont want no smooches from a man! 8O
Minni
Forum Newbie
Posts: 3
Joined: Mon Nov 10, 2003 3:48 pm

Post by Minni »

ROFLMAO :lol:

No worries - I'm female (28) the last time I checked :wink:

I like to sign my posts like that ;-)

Smooches,
Minni
User avatar
Etherguy
Forum Commoner
Posts: 70
Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York

Post by Etherguy »

Minni,

If you want to display a graphic only if a host is alive you will need to check the return code from the system command. Otherwise you will display the graphic whether the host is up or not.

Try this.

Code: Select all

<?php

// ping host and port, direct to null to hide all the system ping garbage

$ping = "ping -c 1 123.456.789:123456 >/dev/null";
system($ping,$ret);

// a return of 0 means the host was alive, anything else and the packet did not make it back

if ($ret == 0) {
echo ""<img src="Alive image">"; 

flush();

}
else {
echo ""<img src="Down image">"; 
flush();
}

?>
Hope that helps a little.
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

we can also check from the output returned by system functions being called
:?:
Post Reply