Revision: 62268
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 12, 2013 22:01 by apphp-snippets
Initial Code
<?php function getRemoteIPAddress(){ $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; return $ip; } /* If your visitor comes from proxy server you have use another function to get a real IP address: */ function getRealIPAddress(){ if(!empty($_SERVER['HTTP_CLIENT_IP'])){ //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; }else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; }else{ $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } ?>
Initial URL
http://www.apphp.com/index.php?snippet=php-get-remote-ip-address
Initial Description
This code allows to get the IP address from which the user is viewing the current page.
Initial Title
Get Remote IP Address in PHP
Initial Tags
php, ip
Initial Language
PHP