Capturing IP Address

Discussion in 'PHP' started by chrisj, Jun 29, 2009.

  1. #1
    I'm using a php script for my web site which has registration, log-in, etc.
    Can you tell me how I might be able to capture the registrants IP adress upon registration? Thanks.
     
    chrisj, Jun 29, 2009 IP
  2. emi87

    emi87 Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $ip = $_SERVER[REMOTE_ADDR];
     
    emi87, Jun 29, 2009 IP
  3. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thanks for your reply.

    If I add $ip = $_SERVER[REMOTE_ADDR]; to my registration page and add a corresponding field in my database, this will allow me to capture the IP address of the regisrtant? Should the db field be named REMOTE_ADDR ?
    Obviously I could use some more information. Any additional enlightening would be appreciated.
     
    chrisj, Jun 29, 2009 IP
  4. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Excluding reserved words, you can name the database field anything you want. It doesn't have to be 'REMOTE_ADDR', but if that will help you associate it with the registrant's IP address use it.

    Also, I don't know why you need to store this in a database, but I would be leary of using it to verify the user. I use multiple computers throughout the day/week each with its own IP address and would be mad if I couldn't log onto a site because I wasn't at the right computer.
     
    plog, Jun 29, 2009 IP
  5. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    Thanks for your reply. I just wanted to capture a users IP address just in case he spams my site, then I could possibly block him, with the thinking that most people use one computer. I don't want to use it as a requirement to log in. A user will just need his user name & password. I look forward to any thoughts/replies regarding this. Thanks.
     
    chrisj, Jun 29, 2009 IP
  6. Hannaspice

    Hannaspice Active Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    Can anybody tell me what is the type of REMOTE_ADDR on database?

    Maybe vchar or int?
     
    Hannaspice, Jul 10, 2009 IP
  7. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #7
    varchar, int only allows numeric characters.
     
    dannywwww, Jul 10, 2009 IP
  8. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #8
    varchar is the best for IPS
     
    Bohra, Jul 10, 2009 IP
  9. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    if your site requires logins use something like this.
    
    $ip = $_SERVER[REMOTE_ADDR];
    $ipselect="select id from user_ips where ip='$ip' and user='$user'";
    $ipquery=mysql_query($ipselect);
    $rows=mysql_num_rows($ipquery);
    if($rows<=0){
    $sql="INSERT INTO user_ips (user,ip)VALUES('$user,'$ip')" or die(mysql_error());
    $query=mysql_query($sql) or die(mysql_error());
    }
    
    PHP:
    That way, whenever your user uses a different IP it will be added. even if a user is on a dynamic ip systems you could narrow things down by the octets on the history.

    Its something I built personally. I do not know if it is the best way of doing things but I figured i share it. You can even go as far as adding dates or timestamps which I should do. Anyway, something to dabble with. enjoy
     
    Dirty-Rockstar, Jul 11, 2009 IP