-
PHP ping user
Hi.
I am trying to create a script to find the ping response time for a user. This is to assist in accurate results with my speedtest.
This is the code I have so far:
Code:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($_GET['n'])) {
$n=10;
} else {
$n = $_GET['n'];
}
$pingme = exec("ping -c$n $ip", $result, $pr);
foreach($result as $data) {
echo $data . "<br />";
}
?>
As far as i know, this scripp should work, which it does on one of my hosts: http://www.skymesh.net.au/~duffell27/ping.php
Thing is I want it on my other host, which does not work: http://speedtest.nicksastronomy.com/ping.php
Is there a php.ini setting i need to ensure is set before this will work? How do I go about fixing this problem?
Thanks in advance.
Nick.
-
Re: - PHP ping user
Hi Nick,
The safe_mode should be ON to be able to execute exec() function. If it’s off then it will not work and to get this on you will have to ask your hosting provider to turn it on for your domain.
Hope this helps!
Cheers,
~Maneet
Lexolution IT Services
Web Design Company
-
-
So, should safe mode be on? or off?
Im gonna see what setting its on now, and see if i can swap it...
-
i have tried setting it to both on and off with my php.ini file.
The script still has not worked.
I am now going to change the php settings to PHP 6 to see if this resolves the problem, as i hear safe mode no longer exists in it
Nick.
-
Before you try that, try this for the following line:
Code:
$pingme = exec("ping -c ".$n." ".$ip, $result, $pr);
Hope this helps.
-
well, nothing seems to be working...
any ideas, anyone?
-
thetestingsite, i tried that line of code with no luck :(
-
OK, i contacted my hosts and they informed me that such a script can not run on their server due security reasons.
Pity, really, but nothing i can do about it.
-
It should be off. It might fail to work if your account has no shell.
Interestingly, it's probably a pretty good idea to stop the amateurs doing this sort of thing — accessing, say, http://yoursite.com/yourscript.php?n=%3Brm%20-rf%20* is liable to delete all your files (you want a couple of calls to escapeshellarg() in there to prevent that, or just an is_numeric() to check $n).
-
It should be off. It might fail to work if your account has no shell.
Interestingly, it's probably a pretty good idea to stop the amateurs doing this sort of thing — accessing, say, http://yoursite.com/yourscript.php?n=%3Brm%20-rf%20* is liable to delete all your files.