Recently I deployed a website in google cloud container cluster, and I believe that the actual website source code is run inside the computer engine instance which created by cluster automatically.
In the website, I want to log the visitor's access info including the public IP address, e.g. 80.87.131.131. But I found that I only can get the internal IP address, like 10.128.0.3
Here is the PHP function I used to get the visitor's IP.
function get_ip()
{
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
return $ip;
}
Is there any way to get the visitor's public IP? Do I need to make some server side configurations? Any help will be appreciated. And thanks very much in advance.