Ryan A wrote:
Will be making two versions, one with a DB and one to work with the file
for the old school folks who dont want to convert their file and use
"new fangled" databases... some people its easier to just not argue or
try to convince...
and however stupid someone's opinion is, they are still entitled to
it...esp when you are thinking of (maybe) selling a future product it
does not make much sense telling them they are stupid :-))
Fair enough.
"If you *need* to stick to using the file, are you looking for a
particular username or just want to load the whole list?"
I'm looking to match a login (user:pass)... so I would need to load the
whole list right? or do you have an alternative idea? am totally open to
suggestions and alternatives at this point... just looking for the
easiest way in terms of server load and processing..which is why I am
trying to avoid a for() or while() loop.
Loops are not evil, but I understand what you're saying. You basically
have a few options. Firstly... is the file in alphabetical order? If yes
then you can use a binary chop algorithm to seek around the file to find
the right line. However, I doubt the file is organised alphabetically, so...
The second option would be to load the entire file into a variable and
do a regex to find the password hash. I'm not great at regexes, but you
want a multi-line regex looking for \n followed by the username,
followed by a :. Should be pretty easy to knock that up. However, this
is not great if the file is not trivial in size.
The third option is to use fgets to read each line in the file, check if
it starts with "username:", and if it does then you've found it. This
would be the slowest option, but the most economical and I think you'd
be surprised at how fast PHP can do this.
Another option would be to break the single file in to several files,
maybe one for each first character. That way you would limit the number
of entries you need to check.
Hope that helps.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php