Previous Article

PHP Function IP if behind a proxy

Next Article

Following from my last post, here is the method to get your IP address if you are behind a proxy.

function getRealIPAddr() {
    // check ip from share internet
    if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
        $ip=$_SERVER["HTTP_CLIENT_IP"];
    } elseif (!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;
}

As this method gets more accurate results it is better to use this than the previous function.

Avatar of Clive Walkden

Clive Walkden

Posted:

Latest Articles

Magento 2 Releases Evolution - Features, Popularity & Issues

Magento 2

A Comprehensive Guide to Major Releases of Magento 2

Explore the evolution of Magento 2 through its major releases, detailing features added, popularity metrics, and issues encountered.

How to Install NordLayer VPN Client on Ubuntu 20.04 and Connect to a Virtual Network

Linux

How to Install NordLayer VPN Client on Ubuntu 20.04 and Connect to a Virtual Network

A simple to follow installation guide for NordLayer VPN

Mastering MySQL Database Imports on Linux - A Comprehensive Guide

MySQL

Mastering MySQL Database Imports on Linux

Learn efficient ways to import MySQL databases on Linux using the mysql command-line client. Explore the --source option and < operator for seamless data migration. Master MySQL imports on Linux with our comprehensive guide.