Jump to content

Log User IP Address in Database


webref.eu

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.