Can't get visitors' IP Address

Discussion in 'PHP' started by fathermarcuss, Oct 2, 2006.

  1. #1
    Hi! I'm new to php and I have this problem that's been bugging me the whole day.

    I learned today that for some reason I cannot get the IP address of the visitors of my site because the $remote_addr function is not working. Is it possible that somebody hacked into my server and somehow disable the function for me? The script was actually working perfectly for a week that's why it beats me that all of a sudden it stopped getting the visitors' IP address and logs on blank on the IP field of my mysql database instead.

    I created a simple script and uploaded it on two different server just to check if it only happens in my server and found out it's working on other server indeed.

    Here's the one that's not working:
    http://www.cjnavato.com/test.php

    This one works:
    http://johnmanalo.freehostia.com/test.php

    The first one display the IP address and my name while the other one only displays my name.

    I only have the following code:

    php:
    <?php
    echo "$REMOTE_ADDR";
    echo "jc";
    ?>

    I've also tried $_SERVER['REMOTE_ADDR'] but it still won't work.

    I hope you guys can help me. I'm more of a designer than a programmer and this is giving me a headache. Sad

    Father Marcuss
     
    fathermarcuss, Oct 2, 2006 IP
  2. Xth Cannon

    Xth Cannon Banned

    Messages:
    352
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't know what version of PHP this was introduced, but is it possible that you are running an old PHP version on your website?

    Try something like this...

    if (getenv(HTTP_X_FORWARDED_FOR)) {
    	$guest_ip = getenv(HTTP_X_FORWARDED_FOR); 
    } else { 
    	$guest_ip = getenv(REMOTE_ADDR);
    }
    
    
    Echo "Your ip is ".$guest_ip;
    Code (markup):
     
    Xth Cannon, Oct 2, 2006 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Barti1987, Oct 2, 2006 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    What happens exactly if you try this:

    <?
    ECHO "Your IP is ".$_SERVER['REMOTE_ADDR']."";
    ?>
    PHP:
    Lee.
     
    BRUm, Oct 10, 2006 IP