Jump to content


Photo

Storing series of related strings.


  • Please log in to reply
5 replies to this topic

#1 Vorotaev

Vorotaev
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationCanada

Posted 06 April 2006 - 05:18 PM

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.

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 April 2006 - 05:34 PM

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 Vorotaev

Vorotaev
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationCanada

Posted 06 April 2006 - 05:40 PM

Ah, that sounds perfect. Thanks very much for your help. ^_^

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 April 2006 - 09:16 PM

And you could even get away with a UNIQUE index on ip_address and then just run INSERT INGOREs.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 06 April 2006 - 09:30 PM

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

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 07 April 2006 - 06:22 AM

Yeah, that's what I meant.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users