Adding a field for IP address

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

Adding a field for IP address

Post by ninethousandfeet »

hello,

i am new to web development and i am currently using mysql and php to make a site. based on your experience, should i add a field to my user table for the ip address when they register? if so, what should the data type be? length? etc.? i've seen varchar(15) from some readings, is that okay?

also, should i have another field for the most recent ip address in the login form? what is the advantage/disadvantage with this?

thanks for the guidance!
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Adding a field for IP address

Post by Apollo »

It not something you "should" do. You can, if you want. But since you ask about the advantage/disadvantage, I assume you don't have a direct need for it.

If you store the IP, you can either use an integer (after ip2long) or just a string (varchar), doesn't matter. Maybe a string is better with IPv6 in mind.
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

Re: Adding a field for IP address

Post by ninethousandfeet »

sounds good. i didn't know if it were something that you should do or not. thanks for the advice.
Post Reply