php question - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: Other (
https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (
https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: php question (
/showthread.php?tid=636601)
php question -
KokyZ - 30.06.2017
hello all boys/girls, please do anyone know how to get Visitor's IP Address on PHP ??
i tried
PHP код:
function GetClientIP($validate = False)
{
$ipkeys = array(
'REMOTE_ADDR',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP'
);
$ip = array();
foreach($ipkeys as $keyword){
if( isset($_SERVER[$keyword]) ){
if($validate){
if(ValidatePublicIP($_SERVER[$keyword]) ){
$ip[] = $_SERVER[$keyword];
}
}else{
$ip[] = $_SERVER[$keyword];
}
}
}
$ip = ( empty($ip) ? 'Unknown' : implode(", ", $ip) );
return $ip;
}
function ValidatePublicIP($ip)
{
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
return true;
}
else {
return false;
}
}
but it always returns Unknown or ::1
please some help
Re: php question -
Meller - 30.06.2017
::1 is basically 127.0.0.1, so it's returning correct.
Re: php question -
KokyZ - 30.06.2017
Quote:
Originally Posted by Meller
::1 is basically 127.0.0.1, so it's returning correct.
|
i was testing it on XAMPP with internet connection but will try testing it on my website...
Re: php question -
]Kurence[ - 30.06.2017
::1 is an IPv6 IP address, what you probably want is IPv4
Re: php question -
AndreiWow - 01.07.2017
PHP код:
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$clientIP = get_client_ip();
Re: php question -
KokyZ - 01.07.2017
thanks all, after testing it on web it worked 100%
+repped