Get Real Client IP Address Of User Machine :
Below code snippet will allow you to retreive the user system IP address, even if user is behind the proxy server.

Example :

 <?php
                               
 function get_client_ip() {
    $ipAddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipAddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipAddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipAddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipAddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipAddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipAddress = 'UNKNOWN';
    return $ipAddress;
    }
 
 $client_ip = get_client_ip();
 echo $client_ip;

 ?>

  /*

  Output :

  172.65.24.12

  */
  
About Me
Rahul Yadav

Rahul Yadav

Technical Architect

Kuala Lumpur, Malaysia

Connect Me:     

I'm a Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.

I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding and technology learning experiences.

In my leisure time, I write technical articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Linux, Angular, Ionic, ReactJS, NodeJS, AJAX, jQuery, Cloud and more.

Tag Cloud