php - Having Users IP Address Showing In My Email Form -
this question has answer here:
- how client ip address in php? 22 answers
hello have created email form unfamiliar how code in section displays users ip address in email sent. here code.
you can't sure of real ip of person using email form because behind proxy or vpn, way best candidate ip address @ time of visit (ref):
function getuserip() { $client = @$_server['http_client_ip']; $forward = @$_server['http_x_forwarded_for']; $remote = $_server['remote_addr']; if(filter_var($client, filter_validate_ip)) { $ip = $client; } else if(filter_var($forward, filter_validate_ip)) { $ip = $forward; } else { $ip = $remote; } return $ip; }
then can add ip information email body with
$mymessage .= "sent ip: " . getuserip() . ".";
further reading: what difference between http_client_ip , http_x_forwarded_for?
Comments
Post a Comment