1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to track ip address with php

Discussion in 'PHP' started by birdsq, Aug 30, 2007.

  1. #1
    Do you know how to track ip with php and to store all the vistors ip
    into my database
     
    birdsq, Aug 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    All different IPs once? Or each time a page is requested, regardless of the existing IPs in the database? Be more specific on what you're trying to accomplish.
     
    nico_swd, Aug 30, 2007 IP
  3. Coder

    Coder Banned

    Messages:
    311
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can use $_SERVER['REMOTE_ADDR']; to get the IP Address of Visitors.
     
    Coder, Aug 30, 2007 IP
  4. birdsq

    birdsq Peon

    Messages:
    810
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    When a page is requested the ip should be added to the database and the time of request.
    Again if a user come from the same ip , it will be recorded with different time
     
    birdsq, Aug 30, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    
    <?php
    // Leave this part out if a connection has been established already:
    $con = mysql_connect('localhost', 'username', 'password') OR die(mysql_error());
    mysql_select_db('database-name', $con) OR die(mysql_error());
    
    // This is necessary:
    mysql_query("INSERT INTO table_name (ipaddress, dateline) VALUES ('". $_SERVER['REMOTE_ADDR'] ."', ". time() .")") OR die(mysql_error());
    
    ?>
    
    PHP:
    Create a table with two columns:
    "ipaddress" - VARCHAR (15)
    "dateline" - INT (10)
     
    nico_swd, Aug 30, 2007 IP
  6. birdsq

    birdsq Peon

    Messages:
    810
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for that
     
    birdsq, Aug 30, 2007 IP
  7. ritadebock

    ritadebock Peon

    Messages:
    344
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ritadebock, Oct 2, 2007 IP
  8. chaku123

    chaku123 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8

    How to track IP address using PHP?
     
    chaku123, Jun 25, 2008 IP