Retrieve local IP address in PHP
Solved
chenille36
Posted messages
10
Status
Member
-
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
Hello,
I’d like to know how to display the local IP address and determine whether it is static or dynamic.
The context is that I’m programming an intranet app that retrieves user information and redirects based on that information.
Thank you.
I’d like to know how to display the local IP address and determine whether it is static or dynamic.
The context is that I’m programming an intranet app that retrieves user information and redirects based on that information.
Thank you.
4 answers
Hello,
To retrieve an IP there aren’t 36 solutions...
<?php /**
* Retrieve the real IP address of a visitor
*/
function get_ip() {
// IP if shared internet
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
}
// IP behind a proxy
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
// Otherwise: normal IP
else {
return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
}
}
?>
but regarding whether it is dynamic or static... I don’t know any way to determine it. (apart possibly, comparing the user’s IP on each visit to see if it matches the previous one... assuming they don’t change computers to connect...)
--
Best regards,
Jordane