Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: PHP ping user

  1. #1
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

  2. #2
    Join Date
    Sep 2008
    Posts
    56
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default 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

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's backwards.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So, should safe mode be on? or off?
    Im gonna see what setting its on now, and see if i can swap it...

  5. #5
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Before you try that, try this for the following line:

    Code:
    $pingme = exec("ping -c ".$n." ".$ip, $result, $pr);
    Hope this helps.
    Last edited by thetestingsite; 11-16-2008 at 04:19 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well, nothing seems to be working...

    any ideas, anyone?

  8. #8
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thetestingsite, i tried that line of code with no luck

  9. #9
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •