Return to Snippet

Revision: 62268
at February 12, 2013 22:01 by apphp-snippets

Initial Code
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(){    
        //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'];
        $ip = $_SERVER['REMOTE_ADDR'];
    return $ip;

Initial URL

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