REMOTE_ADDR IP not works on XAMPP-localhost

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 191
Location: Holland Rotterdam

REMOTE_ADDR IP not works on XAMPP-localhost

I wanna add an ip-adress into an notice script.
This code is working on a hosting server, but not in a script on my XAMPP-home-server

Code: Select all

<? echo $_SERVER['REMOTE_ADDR']; ?>
My question what could i try to do more?
I wanna place the ip-adress in an code, like this, but it is not working into an script on my XAMPP-home-server

Code: Select all

<input type="text" name="from" class="form-control"   readonly="true" value="<? echo $_SERVER['REMOTE_ADDR']; ?>"/></div>
Thank you in advance

Admin
Maybe your apache is listening for IPv6 connections by default, and, if you get the value "::1" for ip address on localhost, it is the equivalent of IPv4 (127.0.0.1).
If you just want IPv4, disable IPv6 connections in your apache configuration:
- Go to XAMPP control panel. Open Apache (httpd.conf), go to Listen (you can Ctrl + F this) which shows 80 (if you have ipv6 active) change it to:

Code: Select all

Listen 0.0.0.0:80
Restart Apache and you will no longer see ::1 in your browser. This will happily return your localhost i.e. 127.0.0.1

JanMolendijk
Dear admin this echo is still not working on my home server XAMPP, into a script what i`m running what could i try to do more ?
i dont even get the value "::1"

Code: Select all

<? echo $_SERVER['REMOTE_ADDR']; ?>
I need the ip-adresses from visitors because i have, a option to add items without registration (to protect)

Admin
I Not know what the problem is.
What value it is returned by $_SERVER['REMOTE_ADDR']?
Try this code to see what exactly it contains:

Code: Select all

var_dump($_SERVER['REMOTE_ADDR']);
- Try also use the function from this example:

Code: Select all

function getIP(){
  return getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?:
 getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?:
 getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR')?:'UNKNOWN IP';
}
$ip = getIP();

//Test
var_dump($ip);

Similar Topics