View Full Version : Collect visitors IP when they click 'Submit'...

03-04-2009, 02:21 AM
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. :)

03-04-2009, 03:13 AM
The code below will help you get the IP address of the user:


03-04-2009, 03:34 AM
This is more safe: :)

function GetUserIP() {
if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
{ $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;

03-04-2009, 03:35 AM
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:

<input type="hidden" value="<?php echo $_SERVER['REMOTE_ADDR']?>" name="ip"/>

How would I work in the safer code you mentioned above?

03-04-2009, 03:48 AM

<input type="hidden" value="<?php echo GetUserIP(); ?>" name="ip"/>

BTW: include my function somewhere before this

03-04-2009, 03:55 AM
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!

03-04-2009, 04:09 AM
Your most welcome!! :thumbsup: