Automatically Log the IP Address of Site Visitor

Discussion in 'MySQL' started by amitash, Dec 17, 2009.

  1. #1
    How can i insert the IP Address of my users into a table automaticaly using the INSERT function.
     
    amitash, Dec 17, 2009 IP
  2. xmart

    xmart Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    definitely can, you need to use
    $REMOTE_ADDR
    PHP:
    in order to collect the user ip address from certain php page.
     
    xmart, Dec 17, 2009 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    You can get IP address in PHP as below..

    $remote_ip = $_SERVER['REMOTE_ADDR']

    and then you can use it in insert query to store in database :)
     
    mastermunj, Dec 18, 2009 IP
  4. amitash

    amitash Well-Known Member

    Messages:
    399
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    125
    #4
    is this correct
     
    amitash, Dec 18, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Nope.
    You are storing IP in date column which is wrong.

    you should add a column in dle_search table "ip_address" and insert ip in that column..

    something like this..

    $remote_ip = $_SERVER['REMOTE_ADDR'];
    mysql_query("INSERT IGNORE INTO dle_search (tag, ip_address) VALUES ('$story', $remote_ip)");
     
    mastermunj, Dec 18, 2009 IP
  6. amitash

    amitash Well-Known Member

    Messages:
    399
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    125
    #6
    What should be the datatype of the ip column. I selected INT
     
    amitash, Dec 18, 2009 IP
  7. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #7
    keep data type as varchar - length 20. If you wish, you can store it as integer value as well but that needs conversion so better store it as it is in varchar field.
     
    mastermunj, Dec 18, 2009 IP
  8. amitash

    amitash Well-Known Member

    Messages:
    399
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    125
    #8
    Thank you for the excellent help. This is the second time you are helping me. I do owe you something man. What can i do for you?
     
    amitash, Dec 18, 2009 IP
  9. kingsoflegend

    kingsoflegend Well-Known Member

    Messages:
    202
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #9
    varchar(15) is enough for IPs
     
    kingsoflegend, Dec 18, 2009 IP
  10. nikes

    nikes Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Which language use are using?
     
    nikes, Dec 31, 2009 IP
  11. suraja

    suraja Peon

    Messages:
    537
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    For crowded website. it will need large CPU performence
     
    suraja, Jan 1, 2010 IP