Jump to content

Archived

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

Vorotaev

Storing series of related strings.

Recommended Posts

I'm trying to write a simple membership system, and for security's sake, I'd like to track the various IP addresses used to access a given account. I obviously don't know what the IP addresses will be in advance, nor do I know how many of them will be used for an account. If the person uses dial-up, it could change with every single visit.

If I knew there would be only one IP address, the situation would be simple; each row would contain a member's screenname, their miscellaneous information, and their IP address all bundled together nice and simple like. But since each member may need to store many IP addresses, I need something a bit more flexible.

MySQL doesn't seem to have any kind of array data type. The closest thing I could find was LONGTEXT, which I could then use to produce a series of IP addresses in CSV format, which I in turn could use a PHP function like explode() to break into an array to work with. It seems like there should be a better way to handle it though.

Any suggestions or information would be appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
your best bet, since you're using a relational database would be to build a related table to store the IPs in. for instance, you'd simply need a table with 2 columns: user_id and ip_address. then, when they log in, you simply check to see whether or not that IP address is stored in relation to that user or not. if so, leave it be; if not, record it.

Share this post


Link to post
Share on other sites
And you could even get away with a UNIQUE index on ip_address and then just run INSERT INGOREs.

Share this post


Link to post
Share on other sites
Not if two users log in from the same IP (public machine, dynamic IP, etc). Could certainly UNIQUE on user_id,ip_address though.

Share this post


Link to post
Share on other sites
Yeah, that's what I meant.

Share this post


Link to post
Share on other sites

×

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.