The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
Get the IP address of the website
<?php
echo 'User IP Address : '. $_SERVER['REMOTE_ADDR'];
?>
/*
I Hope it will help you.
Namaste
Stay Home Stay Safe
*/
$_SERVER['REMOTE_ADDR']
echo $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
function getClientIp(): string
{
//whether ip is from the share internet
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from the proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is from the remote address
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$_SERVER["HTTP_CF_IPCOUNTRY"];
<?php
echo 'User IP Address : '. $_SERVER['REMOTE_ADDR'];
?>
<?php
echo 'IP address of user: '. $_SERVER['REMOTE_ADDR'];
?>
$exec = 'ipconfig | findstr /R /C:"IPv4.*"';
exec($exec, $output);
preg_match('/d+.d+.d+.d+/', $output[0], $matches);
print_r($matches[0]);
$_SERVER['HTTP_ORIGIN']
The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
Get the IP address of the website
<?php
echo 'User IP Address : '. $_SERVER['REMOTE_ADDR'];
?>