$_SERVER['REMOTE_ADDR'] not giving the right ip address
<input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
Don't do that. Get the request from $_SERVER
when the form is submitted. Getting it when the form is generated and storing it in the form just gives people the opportunity to change it.
Does this IP address normally happen when I use it in a localhost (XAMPP)?
Yes. Getting the local IP (IPv6) address is normal when you request a page from localhost.
$_SERVER['REMOTE_ADDR'] not returning IP address
When you have a server on say your laptop, and you try to access it from the same laptop, the website sees it as it self and is represented in many different ways, and here are a few:
127.0.0.1
::1
localhost
To see the IP of your computer you can do the following:
- Put your website on a remote server then access it, this will give you your Public IP address.
- Put your website on another server on the same network and access it from a different computer on that network, and this will give the internal IP address for that computer.
Why is $_SERVER['REMOTE_ADDR'] showing a wrong ip?
I don't care if they are behind a proxy, VPN, etc;
You have to, if they are using a VPN, or a proxy, or NAT then $_SERVER['REMOTE_ADDR']
will contain that ip and not of the user, and that is what you're getting.
UPDATE: I've talked to the specific user in question and he said he is NOT using Google Translate. Why else would a Google IP show in REMOTE_ADDR?
That Google IP you have mentioned in your OP belongs to google-proxy-64-233-173-164.google.com
which is the proxy that this visitor's computer or ISP is using
If you were to check HTTP_X_FORWARDED_FOR
or HTTP_CLIENT_IP
You would get that information
$ _SERVER ['REMOTE_ADDR'] return IP of server, not visitor IP
you may use this function
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$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;
}
$ipaddr = getRealIpAddr();
Load Balancer $_SERVER['REMOTE_ADDR'] Not working
Your webserver receives HTTP requests from the Amazon ELB. Therefore, the remote address will always be one of the ELB ip addresses.
If you need the remote host's address from behind the ELB, get it from HTTP header "X-Forwarded-For".
IP Address of the machine in PHP gives ::1 but why?
::1
is the actual IP. It is an ipv6 loopback address (i.e. localhost). If you were using ipv4 it would be 127.0.0.1
.
If you want to get a different IP address, then you'll need to connect to the server through a different network interface.
Related Topics
Hightest Value of an Associative Array
How to Get List of Supported Encodings by Iconv Library in PHP
In Laravel 5, How to Disable Verifycsrftoken Middleware for Specific Route
Twig Problem with PHP 7.4 in Write Variable
Multiple Routes in Single Route::Get() Call Laravel 4
Trouble Passing Variables to PHP Script on Image Upload
How to Create a New Page in Prestashop Admin Panel
Find a Percentage Value in a String Using Preg_Match
Understanding PHP "Out of Memory" Error
Pdo Mssql Server - Driver Not Found
Codeigniter Command Line Error - PHP Fatal Error: Class 'Ci_Controller' Not Found
How Check Memory Location of Variable in PHP