PDA

View Full Version : PHP ping user



Dr_Nick
11-13-2008, 06:15 AM
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:

<?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.

maneetpuri
11-15-2008, 12:35 PM
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 (http://www.lexolutionit.com)

Twey
11-15-2008, 07:47 PM
That's backwards.

Dr_Nick
11-16-2008, 03:08 AM
So, should safe mode be on? or off?
Im gonna see what setting its on now, and see if i can swap it...

Dr_Nick
11-16-2008, 03:52 AM
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.

thetestingsite
11-16-2008, 04:14 AM
Before you try that, try this for the following line:



$pingme = exec("ping -c ".$n." ".$ip, $result, $pr);


Hope this helps.

Dr_Nick
11-16-2008, 04:18 AM
well, nothing seems to be working...

any ideas, anyone?

Dr_Nick
11-16-2008, 04:21 AM
thetestingsite, i tried that line of code with no luck :(

Dr_Nick
11-16-2008, 04:42 AM
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.

Twey
11-16-2008, 08:31 AM
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 (http://www.php.net/escapeshellarg)() in there to prevent that, or just an is_numeric (http://www.php.net/is-numeric)() to check $n).

Twey
11-16-2008, 08:31 AM
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.