PHP Get User IP Address

Today, We want to share with you PHP Get User IP Address.In this post we will show you get public ip address in php, hear for how to get system ip address in php we will give you demo and example for implement.In this post, we will learn about how to get current system ip address in php with an example.

PHP Get User IP Address

There are the Following The simple About PHP Get User IP Address Full Information With Example and source code.

As I will cover this Post with live Working example to develop php get computer name from ip address, so the some undefined index: http_client_ip for this example is following below.

This PHP general first attempts to grab data the user’s fetch IP from other any server side variables (which take proxies into account) before some data of the resorting to REMOTE_ADDR.

index.php


    function fetchUserIP() {
    	$clientIpAddress = '';
    	if (isset($_SERVER['HTTP_ORIGINAL_IP']) && !empty($_SERVER['HTTP_ORIGINAL_IP']))
    		$clientIpAddress = $_SERVER['HTTP_ORIGINAL_IP'];
    	elseif (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']))
    		$clientIpAddress = $_SERVER['HTTP_CLIENT_IP'];
    	elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    		$clientIpAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    	elseif (isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    		$clientIpAddress = $_SERVER['REMOTE_ADDR'];	
    	
    	return $clientIpAddress;
    }

How to Get IP Address of User in PHP

sometimes you have REMOTE_ADDR does not perfect returns the correct or reall IP address of the each clients user

get real IP address of user in PHP source code

function fetchUserIP(){
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        //clientIpAddress from share internet
        $clientIpAddress = $_SERVER['HTTP_CLIENT_IP'];
    }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        //clientIpAddress pass from proxy
        $clientIpAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
        $clientIpAddress = $_SERVER['REMOTE_ADDR'];
    }
    return $clientIpAddress;
}

echo 'User Display Real IP Address- '.fetchUserIP();
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Get User IP Address.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment