Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Pennsylvania, United States
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Lightbulb Collect visitors IP when they click 'Submit'...

    Hello there, everyone.

    Thanks for taking the time to read my thread. I was wondering if anyone knew how I could adapt a form I have to collect the person's IP Address when they submit it.

    Here is the link to the form: http://www.bucketbux.com/referralspam.php

    The form automatically sends me an e-mail with all of the information. I just need their IP Address to be included. Any advice is greatly appreciated!

    Thank you.

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ohio
    Posts
    254
    Thanks
    1
    Thanked 63 Times in 63 Posts
    The code below will help you get the IP address of the user:
    PHP Code:
    $ip=$_SERVER['REMOTE_ADDR']; 

  • Users who have thanked shadowmaniac for this post:

    Kovich (03-04-2009)

  • #3
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    This is more safe:
    PHP Code:
        function GetUserIP() {
              if (isset(
    $_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) 
                                        { 
    $ip $_SERVER["HTTP_X_FORWARDED_FOR"]; } 
                                     elseif(isset(
    $_SERVER["HTTP_CLIENT_IP"])) 
                                        { 
    $ip $_SERVER["HTTP_CLIENT_IP"]; } 
                                     else { 
    $ip $_SERVER["REMOTE_ADDR"]; }
                                   }  
              else { if ( 
    getenv'HTTP_X_FORWARDED_FOR' ) ) 
                          { 
    $ip getenv'HTTP_X_FORWARDED_FOR' ); } 
                     elseif ( 
    getenv'HTTP_CLIENT_IP' ) ) 
                          { 
    $ip getenv'HTTP_CLIENT_IP' ); } 
                     else { 
    $ip getenv'REMOTE_ADDR' ); }
                   }
              return 
    $ip;     
        } 

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Pennsylvania, United States
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Fantastic, thanks a lot!

    I did some editing of my page, and with that snippet there I got it to work. I appreciate the assistance. Have a wonderful day.

    EDIT: Okay, what I did was place this into the form, and then just added the proper information so that it would be sent in the e-mail:

    PHP Code:
    <input type="hidden" value="<?php echo $_SERVER['REMOTE_ADDR']?>" name="ip"/>
    How would I work in the safer code you mentioned above?

  • #5
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Try:

    PHP Code:
    <input type="hidden" value="<?php echo GetUserIP(); ?>" name="ip"/>
    BTW: include my function somewhere before this

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Pennsylvania, United States
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Alright. I put the function into the script then replaced the input type with what you gave me above.

    I tested it - and it works! Fantastic. I'm happy. Thanks again, sea4me!

  • #7
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Your most welcome!!

    lol


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •