Do you want to know the IP address of your website visitors? The following PHP code sample below will show you the IP address of a web page visitor. You may use something as simple as this to start to track your visitors and site members.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function getUserIPaddress() { if(!empty($_SERVER['HTTP_CLIENT_IP'])){ //ip from internet $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ //ip pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; }else{ $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } $userIP = getUserIPaddress(); echo "$userIP"; |
Find more cool PHP snippets like this in our PHP category.