View Full Version : Track IP addresses using submit forms?


ibii
02-16-2007, 12:57 AM
Hey everyone,

I was just wondering if there's anyway possible not only to track someone's IP, but also have that IP address e-mailed to me in a form after they hit submit. That is, the visitor will fill out the form and after they hit submit, the information on the form as well as their IP address is sent to my e-mail. (Of course the visitor will also be notified that their IP address is being tracked.) Is this possible? Sorry that I'm not sure which forum to post this in, please move if necessary. Thank you.

ibii
02-16-2007, 09:23 AM
I found a free PHP script online somewhere that claims it will e-mail me the visitor's IP address once they have submitted the form, but I can't get it to work properly. The instructions say that all I have to do is change the e-mail addresses/company name so that it will send to my e-mail, and then place the code within <body> tags of a document that has a .php extension. The script does send something to my e-mail, but everything is blank. (No IP address listed, no nothing.) Why is this?? EDIT: The script below is placed with the <body> tags of a document that is normally structured as an HTML document, but renamed with a .php extension. Below is the script I used:

<?php

$A = $HTTP_USER_AGENT;
$B = $HTTP_REFERER;
$C = $SERVER_PROTOCOL;
$D = $HTTP_CONNECTION;
$E = $SERVER_SIGNATURE;
$F = $HTTP_REFERER;
$G = $REMOTE_USER;
$H = $REMOTE_HOST;
$I = $QUERY_STRING;
$J = $SERVER_ADDR;
$K = $HTTP_ACCEPT_LANGUAGE;
$L = $HTTP_ACCEPT;
$M = $HTTP_USER_AGENT;
$N = $GATEWAY_INTERFACE;
$O = $HTTP_HOST;
$P = $SERVER_SOFTWARE;
$Q = $SERVER_ADMIN;
$R = $REMOTE_ADDR;
$S = $SCRIPT_NAME;
$T = $HTTP_X_MCPROXYFILTER;
$U = $USER;
$V = $SERVER_NAME;
$W = $DOCUMENT_ROOT;
$X = $REQUEST_URI;
$Y = $HTTP_COOKIE;
$Z = $REMOTE_PORT;
$ip =$REMOTE_ADDR;
$admin_email = "YOUR@EMAIL ADDRESS.COM ";
$bcc_email = "OTHER@EMAIL ADDRESS.COM ";
$company_name = "AMERICAN FINANCING ";
$to = $admin_email;
$subject = 'Web Page Visitor';
$body .= "IP Address: $ip has visited this web page\n\n";
$body .= "A: $A\n";
$body .= "B: $B\n";
$body .= "C: $C\n";
$body .= "D: $D\n";
$body .= "E: $E\n";
$body .= "F: $F\n";
$body .= "G: $G\n";
$body .= "H: $H\n";
$body .= "I: $I\n";
$body .= "J: $J\n";
$body .= "K: $K\n";
$body .= "L: $L\n";
$body .= "M: $M\n";
$body .= "N: $N\n";
$body .= "O: $O\n";
$body .= "P: $P\n";
$body .= "Q: $Q\n";
$body .= "R: $R\n";
$body .= "S: $S\n";
$body .= "T: $T\n";
$body .= "U: $U\n";
$body .= "W: $V\n";
$body .= "X: $W\n";
$body .= "Y: $X\n";
$body .= "Z: $Y\n";
$headers = "From: $company_name <$admin_email>\r\n";
$headers .= "Bcc: $bcc_email";
// $headers .= "X-Sender: <$admin_email>\n";
// $headers .= "X-Mailer: PHP\n";
mail ($to, $subject, $body, $headers);
?>

decepti0n
02-16-2007, 10:42 AM
Their IP is in $_SERVER['REMOTE_ADDR'], don't really know if those ones up there work. Just get that in a variable and add it to the email (if you know a bit of PHP).

I think if they're using a proxy, then use $_SERVER['HTTP_X_FORWARDED_FOR'].

ibii
02-16-2007, 11:37 AM
>_< Ahhh my god, thank you so much for your reply, but I did figure out what was wrong with the script. The only problem was that the e-mail used $ip instead of $ipaddress, which was the original variable. All I had to do was change the $ip to $ipaddress and it worked perfectly fine. Thank you so much for the proxy server, though, I was about to request that next. Thank you!! :D

bejayel
02-18-2007, 07:13 AM
have to be careful with that script because the IIS PHP doesnt act the exact same as the Apache PHP. So you might get wierd activity if your using IIS and PHP