<?php function ping($host) { exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval); return $rval === 0; } $hosts_to_ping = array('RANDOM_IP', '127.0.0.1'); ?> <ul> <?php foreach ($hosts_to_ping as $host): ?> <li> <?php echo $host; ?> <?php $up = ping($host); ?> (<img src="<?php echo $up ? 'on' : 'off'; ?>" alt="<?php echo $up ? 'up' : 'down'; ?>">) </li> <?php endforeach; ?> </ul>
PHP Ping
PHP Ping
I stumbled across this code and tried running it but it always seems to return "down" or "off" - Can anyone see whats wrong?
Last edited by Helx on Tue Nov 13, 2012 11:28 am, edited 1 time in total.
Reason: Not too sure if you put a real IP or an internal one... Would rather not risk it :)
Reason: Not too sure if you put a real IP or an internal one... Would rather not risk it :)
Re: PHP Ping
Are you hosting this yourself or do you use a professional/free host?
Most hosts disable those commands due to malicious activities.
By the way, works fine for me
Most hosts disable those commands due to malicious activities.
By the way, works fine for me
Re: PHP Ping
i was just using xammp on my pc for now, how do i enable this on there?
Re: PHP Ping
Just look for your php.ini file, there are a bunch of options in there.
I believe you need to look for "Safe_mode" or something.
XAMPP, isn't that program limited to local connections only?
You may have to allow it to bypass firewalls and whatnot if you want outbound connections.
I believe you need to look for "Safe_mode" or something.
XAMPP, isn't that program limited to local connections only?
You may have to allow it to bypass firewalls and whatnot if you want outbound connections.
Re: PHP Ping
That looks like the Linux ping command, if you are running Windows it's not going to work