PHP Basics

Use PHP To Get The Real IP Address


If you want to record the visitors IP Address there are a few things you need to remember, computers on shared internet connections can have different IP Addresses and visitors coming to your website through a proxy will have different IP addresses.

Computers coming through a proxy, the IP address will come through as the proxy IP address.

Below is a PHP snippet which you can use which will get the real IP Address of the visitor.

function getRealIpAddr()
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    return $ip;
Back to top

Gain access to all tutorials

  • Premium tutorials covering WordPress, Laravel and VueJS
  • Download premium content
  • Download premium WordPress plugins
  • Only $5 a month

Join Paulund