webref.eu Posted December 20, 2008 Share Posted December 20, 2008 Hi All I want to log the user IP address in my database when they register for my site. Can anyone give me the best technique? Thanks Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/ Share on other sites More sharing options...
graham23s Posted December 20, 2008 Share Posted December 20, 2008 Hi Mate, you could do: $ip = $_SERVER['REMOTE_ADDR']; then store $ip in the correct table row Graham Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720474 Share on other sites More sharing options...
ILMV Posted December 20, 2008 Share Posted December 20, 2008 Yes, you get their IP, and store it in a database There are no other techniques $_SERVER['REMOTE_ADDR'] That gets the IP, do you know how to add it to a database? Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720475 Share on other sites More sharing options...
webref.eu Posted December 20, 2008 Author Share Posted December 20, 2008 That gets the IP, do you know how to add it to a database? I know how to add data into database fields, but is there any special formatting or validation usually necessary when adding IP addresses. I'll just use an integer field, right? Thanks Guys Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720479 Share on other sites More sharing options...
ILMV Posted December 20, 2008 Share Posted December 20, 2008 It cannot be an integer because of the the dots, use a varchar length 15 Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720482 Share on other sites More sharing options...
lanmonkey Posted December 20, 2008 Share Posted December 20, 2008 I use this: $ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR'])) which converts the ip to an unsigned integer making it very easy to store and do operations on, like find out if the ip is in a blocked range this method is listed on the ip2long() page in the php manual http://uk.php.net/ip2long Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720486 Share on other sites More sharing options...
webref.eu Posted December 20, 2008 Author Share Posted December 20, 2008 Thanks for your comments guys. I think I will stick with dot decimal format for now. If I use varchar length 15, I assume that will cover all possible current IP addresses. Would it cope with IPv6 when that is introduced or is that not worth worrying about? Rgds Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720501 Share on other sites More sharing options...
ILMV Posted December 21, 2008 Share Posted December 21, 2008 No it wouldn't cope with IPv6 because of the length of the address. 15 chars is enough... 255.255.255.255 <- is the biggest IP you can have. 15 characters Link to comment https://forums.phpfreaks.com/topic/137858-log-user-ip-address-in-database/#findComment-720674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.