SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Logging Users IP

    I'm making a Admin control panel, and I want to log all the IP's that are going to it.... How would I go about doing this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Kentucky, USA
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your using mysql then...

    PHP Code:
    $query "INSERT INTO table (ip) VALUES ('{$_SERVER['REMOTE_ADDR']}')";
    mysql_query($query); 
    Make sure you have unique ID's for each ip in the table or something like that.

  3. #3
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool i'll do that once i have my database running, is there some way just to write it to a file right now?

  4. #4
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this, "I think"
    PHP Code:
    $fp fopen("ips.txt""a");
    fputs($fp$_SERVER['REMOTE_ADDR']."\r\n");
    fclose($fp); 
    And that should write each IP on a new line.
    Last edited by notepad_coder; Jun 13, 2002 at 13:36.
    - the lid is off the maple syrup again!

  5. #5
    SitePoint Member Rupert's Avatar
    Join Date
    May 2002
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Try THis out

    Ok try this

    <?php

    gethostbyaddr($REMOTE_ADDR);
    $filename = "rupert.log";
    $datearray = getdate();
    $year = $datearray["year"];
    $month = $datearray["mon"];
    $day = $datearray["mday"];
    $hour = $datearray["hours"];
    $minute = $datearray["minutes"];
    $fl=fopen($filename,'a');
    fwrite ($fl, "[$month/$day/$year, $hour:$minute] $REMOTE_ADDR");
    ?>

    I hope it works
    www.bonfire.tk

  6. #6
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rupert your code works great! Thanks!

  7. #7
    SitePoint Member Rupert's Avatar
    Join Date
    May 2002
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks
    www.bonfire.tk

  8. #8
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for that ftp function, couldn't you also use a+? would that make a huge difference? then you could read it, too. right?
    Ryan

  9. #9
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The REMOTE_ADDR environment variable will not always contain the IP of the person viewing a page, for example if they use a proxy server. So you should check for the presence of X_FORWARDED_FOR - if it is set, then it will give the real IP of the user if they are using a proxy server.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  10. #10
    SitePoint Member Rupert's Avatar
    Join Date
    May 2002
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    X_FORWARDED_FOR is there any other information i could read about. I'm kind of curious about it.
    www.bonfire.tk

  11. #11
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't really know of any official place about it. just check to see if it exists, and if it does, i guess use it instead of REMOTE_ADDR. it can, however, be spoofed into anything since it's sent by the client (unlike REMOTE_ADDR). it is sent by the client in the X-Forwarded-For: header and is available in PHP via $_SERVER['HTTP_X_FORWARDED_FOR'].

    there are some other ones like HTTP_CLIENT_IP, but i don't know what's used when. i guess it depends on the proxy.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


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
  •