Need to capture spammers IP address in my contact form...

Discussion in 'PHP' started by timothius, Jun 5, 2008.

  1. #1
    Hi all!

    A really quick question. I want to pass the IP address of anyone who submits a form to me on my site through a hidden field. I can then easiliy take action and block the spammers very easily.

    Question is how do I capture the IP and stick it in the form? THANKS!
     
    timothius, Jun 5, 2008 IP
  2. orlandolukas

    orlandolukas Guest

    Messages:
    118
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    well



    $ip=@$REMOTE_ADDR;
    echo "<input type='hidden' value='$ip' />";


    This is the code and here is your IP address= 68.250.203.233

    IP address if the register_global is off
    If at php.ini if register_global is set to Off then we have to change the script a bit to get the address. Here it is

    $ip=$_SERVER['REMOTE_ADDR'];
     
    orlandolukas, Jun 5, 2008 IP
  3. timothius

    timothius Active Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks for the reply. I actually now have the code I need to capture the IP address. I call an ip cature function put the value in a variable called $ip. Now, I want to send it back to me in an email message along with the actual information sent to me by the user.

    Question is, my form is a here doc. I currently have my hidden input field setup like this: <input type="hidden" name="ipaddress" value='$ip'>.

    Which doesn't work. :(
     
    timothius, Jun 5, 2008 IP
  4. orlandolukas

    orlandolukas Guest

    Messages:
    118
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i need to see the script
     
    orlandolukas, Jun 5, 2008 IP
  5. timothius

    timothius Active Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Ok sorry, now I need to rephrase my request which is...

    How do I insert a variable INSIDE of a here doc?

    Example:


    <?php
    print<<<_FORM

    <input name="ipaddy" type="hidden" value="<?php echo $ip ?>"/>

    <textarea cols="40" rows="7" name="message"></textarea>

    <input name="submit" type="submit" value="Click to Send"/>

    _FORM;
    ?>


    The above example doesn't work.... the area in red needs help. :(
     
    timothius, Jun 5, 2008 IP
  6. timothius

    timothius Active Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #6
    No need for a reply - I had someone over at phpfreaks.com fix the problem. ;)
    Thread closed.
     
    timothius, Jun 5, 2008 IP