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.
Results 1 to 3 of 3

Thread: IP Log

  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts

    IP Log

    Ive made ip logger for my site. Is there anyway to make it so that it only logs the same ip once a day e.g. 75.64.0.1 so that it doesnt apper in the log more than once? Also i was looking to make it so it only displays 25 ip's on a page and when 25 ip's are logged it automaticly creates a new page.
    Thanks

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    I'm assuming you're using a database?

    If so, to only log one IP per day

    iplogger.php
    PHP Code:
    //assumes you're already connected to the database
    $ip $_SERVER['REMOTE_ADDR'];
    //This assumes you have a variable with todays date named $date
    $query "SELECT * FROM `table` WHERE `date_inserted` = $date AND `ip` = $ip";
    $result mysql_query($query);
    if(
    mysql_num_rows($result) > 0)
    {
    //There is already an IP from today in the database
    $addip false;
    }
    else
    {
    $addip true;
    }
    if(
    $addip)
    {
    $query "INSERT INTO `table`(columns here) VALUES (values here)";

    Using a database, you only need one page to display all the IPs. You can limit the number shown by only withdrawing 25 IPs at a time. Using a $_GET var, the page can figure out which set of results to pull from the database:

    http://www.mysite.com/showips.php -- shows IPs 1-25
    http://www.mysite.com/showips.php?page=2 -- shows IPs 26-50
    http://www.mysite.com/showips.php?page=3 -- shows IPs 51-75
    etc...

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts
    thanks ill give it a try


  •  

    Posting Permissions

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