I stumbled across this code and tried running it but it always seems to return "down" or "off" - Can anyone see whats wrong?
[syntax=php]
<?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>
[/syntax]
PHP Ping
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![Smile :)](./images/smilies/icon_e_smile.gif)
Most hosts disable those commands due to malicious activities.
By the way, works fine for me
![Smile :)](./images/smilies/icon_e_smile.gif)
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 ![Razz :P](./images/smilies/icon_razz.gif)
![Razz :P](./images/smilies/icon_razz.gif)