PHP - IP address reflected as 127.0.0.1

I am new to PHP.

I would like the IP address when I used the HotSpot screen to display on my web page, I (I only, I modified the hosts file for the HotSpot screen web page), but, unfortunately, this was reflected as 127.0.0.1 The main goal is that when I connect, the IP address that I have set is displayed on the page. Here is the code I used:

<?php $rmt = $_SERVER["REMOTE_ADDR"]; echo "$rmt \n" ?>

The only problem is that $ rmt is 127.0.0.1. Do any of you know how to make it display the public IP address that will be displayed?

+3
source share
3 answers

$_SERVER['REMOTE_ADDR'] IP-, . , ip (127.0.0.1 "localhost" ).

ip, ( -) .

+1

-; , , var_dump($_SERVER); , X-Forwarded-For X-Real-IP

+4

I had the same problem. As it turned out, I was getting the proxy IP address instead of my own IP address. So I ran:

var_dump($_SERVER) 
//you could also use print_r($_SERVER);

And then searched for something like this:

 ["HTTP_X_REAL_IP"]

Then captured it in var as follows:

$ip = getenv('HTTP_X_REAL_IP')
+1
source

All Articles