Get IP Address Of User Submitting Contact Us Form

Discussion in 'Programming' started by N€O, Feb 20, 2009.

  1. #1
    Hello,

    I'm using formmail script for the contact us form. But is there any way to capture the IP adress of the form submitters? Using the same script or by using additional one along with it..???

    - N€O
     
    N€O, Feb 20, 2009 IP
  2. vikassah

    vikassah Peon

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can get the user's IP using the environment variable REMOTE_ADDR

    or better still move to cforms (a highly configurable form script)
     
    vikassah, Feb 20, 2009 IP
  3. CreatorKit.com

    CreatorKit.com Active Member

    Messages:
    581
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #3
    $_SERVER['remote_addr'] always contains USER's IP... so just post it to your form as hidden, or use it in final loaded script without any forms, that's better...
     
    CreatorKit.com, Feb 20, 2009 IP
  4. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sometimes, if a user is accessing your site through a proxy, the proxy will pass your site their real IP. This is stored in $HTTP_X_FORWARDED_FOR
    You should check if this is set and then, if it is, assume that to be their real IP, else, assume the IP given by $_SERVER['remote_addr'] to be the real IP.
    If you need any help scripting this, just ask. I hope I helped. :)
     
    thefluffball, Feb 20, 2009 IP
  5. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #5
    <input type="hidden" name="userIP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>">
    PHP:
    Add this code ( input field ) into your form ( no worries, it's invisible ) and whoalaa .. :)
     
    ActiveFrost, Feb 20, 2009 IP
  6. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No, that can be tampered with. Code it directly into the PHP script.
     
    thefluffball, Feb 20, 2009 IP
  7. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #7
    I can use Proxy instead of editing hidden fields .. what you are going to do in that case ? :rolleyes: From my point of view, if you do not add proxy verification, you can use both codes ( as there is no difference between them ).
     
    ActiveFrost, Feb 20, 2009 IP
  8. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Read my post from above: http://forums.digitalpoint.com/showpost.php?p=10686273&postcount=4
    Also, using your method, to prevent possible code injections and other vulnerabilities, you will have to validate the IP in the PHP script anyway. Moreover that, what extra trouble is it having another line in a PHP script; than having 1 line to retrieve the IP from post/get, then validate it, and having an extra line in your HTML. Point taken? ;)
     
    thefluffball, Feb 20, 2009 IP
  9. N€O

    N€O Member

    Messages:
    232
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #9
    N€O, Feb 21, 2009 IP