Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Finding IP address

    Hi,

    I have tried a few pieces of code to find and echo the IP adress in a page but have not had any success. Im sure its fairly simple but i cant do it!

    Can someone please tell me how to do this sucessfully.
    Andrew,
    AKA ItsMe

  • #2
    New Coder
    Join Date
    Jan 2005
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    echo $_SERVER['REMOTE_ADDR'];
    ?>
    or you can do this

    PHP Code:
    <?php
    $IP 
    $_SERVER['REMOTE_ADDR'];

    echo 
    $IP;
    ?>

  • #3
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That doesnt work, it just comes up blank.

    Any ideas?
    Andrew,
    AKA ItsMe

  • #4
    New Coder
    Join Date
    Jan 2005
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does your webserver even support php?? lol

  • #5
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yes it does, im running several PHP scripts on it.
    Andrew,
    AKA ItsMe

  • #6
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The following is the code i am using.

    PHP Code:
    Your IP is: <?php echo $_SERVER['REMOTE_ADDR']; ?>
    It outputs "Your IP is: "
    Andrew,
    AKA ItsMe

  • #7
    New Coder
    Join Date
    Jan 2005
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you send me your url?

  • #8
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Andrew,
    AKA ItsMe

  • #9
    New Coder
    Join Date
    Jan 2005
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    echo "<font color=\"black\">$_SERVER['REMOTE_ADDR']</font>";
    ?>
    Maybe it blends in, lol. I am sorry, I have not a clue. This happened to me ages ago and I don't know how I fixed it.

  • #10
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, thanks for your help. If you find a solution please let me know otherwise no problems.

    Thanks again!
    Andrew,
    AKA ItsMe

  • #11
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    unless that kind of thing has been somehow disabled by your host, I'm using <?php echo $_SERVER['REMOTE_ADDR']; ?> and it work's fine

  • #12
    New Coder
    Join Date
    Mar 2005
    Location
    UK
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Is there any other way of doing this or not?
    Andrew,
    AKA ItsMe

  • #13
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    $_SERVER array values are set by the server. If they're not set you should ask the admin why the server doesn't set them. Create a page with
    PHP Code:
    <?php phpinfo(); ?>
    in it and search for REMOTE_ADDR and to what it's set.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #14
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    It would be extremley weird IWHT that $_SERVER variables be disabled...

  • #15
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try
    PHP Code:
    echo getenv('REMOTE_ADDR'); 


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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