How should I call this function? I'm new to PHP. Here's my code... but I have an error
Notice: Undefined variable: ip in C:\xampp\htdocs\PHPTest\ip.php on line 19
<?php
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;
}
call_user_func('getRealIpAddr', '$ip');
echo $ip;
?>
UPDATE
Strange reason, I'm using Windows 10, localhost, xampp and google Chrome this script doesn't provide me an ip address! That's why a corrected code was empty... Thought it was some kind of errors or something
Second UPDATE
If you're getting no ip like me, you may try this solution on httpd.conf