PHP script in form for capturing users IP

Discussion in 'PHP' started by espmartin, Jul 31, 2007.

  1. #1
    Hello All,

    I would like to capture a users IP when they fill out a form. Once that form is
    submitted, I would like to also submit the IP as well.

    If the form I get via email contains spam, I'd like to deny that IP in my htaccess file.

    Can I get a sample PHP script to do this?
     
    espmartin, Jul 31, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Do you wan't the whole process to be automatic, or can you manually modify the .htaccess file?

    Also one thing that's bad about this, is that someone can be using a proxy and you wouldn't be banning their actual IP.

    
    
    //ipaddress
    $ipAddress = $_SERVER['REMOTE_ADDR'];
    
    mail("your@email.com", "IP ADDRESS", $ipAddress);
    
    
    PHP:
     
    jestep, Jul 31, 2007 IP
  3. espmartin

    espmartin Well-Known Member

    Messages:
    1,137
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Yes. Is there any way to "fool proof" this, so even beginner to intermediate hacks
    can't get around this?
     
    espmartin, Jul 31, 2007 IP
  4. espmartin

    espmartin Well-Known Member

    Messages:
    1,137
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Yes, I have access to htaccess (preferred method). As PHP goes, please be patient
    with me! That 1st line ($ipAddress =) - that goes on my page w/the form?
    The second line of code (mail("your...") ) goes on my "submission page" - the one
    the form points to?
     
    espmartin, Jul 31, 2007 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    I would put all of it on the same page that processes the form data. This way there is less chance of a user trying to manipulate the data.

    I don't know of any way to get around proxies. You could try to integrate with a system like http://www.projecthoneypot.org/. This way you can prevent bad IP's from even accessing your site in the first place.
     
    jestep, Jul 31, 2007 IP