Get Users IP Address
A simple function to get your users ip address. Whether you want to log their ip address as part of their online activities, or authenticate/whitelist them by ip address, the following function will get you the ip address. It also grooms the ip address by removing anything that is not a number or a period. This function will return the forwarded-for address if it exists as well.
function get_user_ipaddress(){ $ipaddress = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'] ; return ereg_replace('([^[:digit:]\.])','',$ipaddress); }
About this entry
You’re currently reading “Get Users IP Address,” an entry on PHP Functionalism
- Published:
- 9.1.11 / 5pm
- Category:
- Tips & Tricks
- Tags:
No comments
Jump to comment form | comments rss [?] | trackback uri [?]