我遇到了一些问题,我需要知道如何在我的网站上获取用户的IP地址,并且我正在使用此代码:
$ip = $this->input->ip_address() ;
echo $ip;
这将返回我的主机IP,谢谢您的帮助
答案 0 :(得分:0)
Use this function instead of it.
function get_ip_address_of_user() {
$ipaddress = array();
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress['ip'] = $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress['ip'] = $_SERVER['HTTP_X_FORWARDED'];
else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress['ip'] = $_SERVER['HTTP_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_FORWARDED']))
$ipaddress['ip'] = $_SERVER['HTTP_FORWARDED'];
else if (isset($_SERVER['REMOTE_ADDR']))
$ipaddress['ip'] = $_SERVER['REMOTE_ADDR'];
return $ipaddress;
}