How to get IP address of visitor and save it to database ?

Discussion in 'PHP' started by ziya, Jun 28, 2007.

  1. #1
    Hey guys,

    I have a registration form. Users are registering via that form. But I want to save user's IP address to Database too. How can I get IP address of user ?

    Thank you in advance
     
    ziya, Jun 28, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    $_SERVER['REMOTE_ADDR'] though it's almost pointless. not all ip addresses' are static.
     
    ansi, Jun 28, 2007 IP
  3. ziya

    ziya Well-Known Member

    Messages:
    1,971
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thank you for your reply . Can I just write it like this :

    update table_name set Ip_add=$_SERVER['REMOTE_ADDR'] ?
     
    ziya, Jun 28, 2007 IP
  4. Darc

    Darc Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah although most IPS are dynamic meaning they change on a scheduled time period... most IPS DO NOT change according to the time frame of the lease. As long as my modem is online at the time of the lease renewal I can keep an IP up to 12 months before the DNS servers force a change. So it's not entirely pointless. I worked for an ISP for 6 months :) learned lots of nice tricks.
     
    Darc, Jun 28, 2007 IP
  5. ziya

    ziya Well-Known Member

    Messages:
    1,971
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Can ISP recognize my local network IP address ? Do they making this kind of logs ?
     
    ziya, Jun 28, 2007 IP
  6. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #6
    so on dialup, you're going to stay connected for 12 months just to keep your ip address? it's pointless like i said. each time someone with a dialup connection disconnects and reconnects, their ip address is different in most cases. why else would you log ip addresses anyways? i mean it'd definitely useful to log ip's for various reasons. to check against fraud and all of that stuff with geo location and what not. all i am saying is that it's not going to be the same everytime so i hope he isn't basing his login system on it.
     
    ansi, Jun 28, 2007 IP
  7. ziya

    ziya Well-Known Member

    Messages:
    1,971
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #7
    How can I do adminstrative side of managing users ( blocking some users to access the site, if there will be any need ?) I thought If I will have IP adress, they will be responsible what they do at site. What can you offer to manage this kind of problems , if not to log IP addresses of users .

    Thank you
     
    ziya, Jun 28, 2007 IP
  8. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #8
    then yeah, blocking their ip address would be the route to go. maybe even a mask of their ip address since it's not the whole thing that changes, just part of it. though this will result in others being banned as well but it's the price you pay. if not just ban the one ip address and then if it changes or renews and they return, ban them again.
     
    ansi, Jun 28, 2007 IP
  9. Darc

    Darc Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    lmfao I'm on on dialup ANSI... I'm on premium cable.... piss on dialup... but anywho as for blocking IP addresses, you can simply use a .htaccess file and include the following:

    <Files .htaccess>
    order allow,deny
    deny from all
    </Files>

    then you just add the ip like this:
    deny from xxx.xxx.xxx.xxx

    or to deny an entire range just add:
    deny from xxx (e.g. 172 will deny any ip beginning with 172, which is typically used by AOL)
     
    Darc, Jul 9, 2007 IP
  10. pfek

    pfek Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #10
    Throw back the handling of directories of your website by using an .htaccess...entering them by hand directly in the file would be quite a job if you have a lot of users.

    From your php file, you can forward them to the user part of the site if they are allowed to, or to any other banned page you want them to view.

    This method is cool, I think, because you can set up some kind of user/groups who have access to sections of your site depending of their settings. It's easy to do all of that directly in php
     
    pfek, Jul 9, 2007 IP
  11. kajol

    kajol Well-Known Member

    Messages:
    523
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #11
    Yes, for common use: $_SERVER['REMOTE_ADDR']
    for proxy use: $HTTP_X_FORWARDED_FOR
     
    kajol, Jul 9, 2007 IP
  12. Darc

    Darc Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    hey I didn't know about the proxy part, that's cool
     
    Darc, Jul 12, 2007 IP