Hey you could do it either way. Speed ... I dunno which would be faster. Guess it all depends on the box your using. Plus how many other sessions are open on the database. Anyway, let's assume it would be faster to have the ID searched instead of the username:
Here is how you would implement that:
I am assuming all usernames already have a field in your table that has something along the lines of ..
table_id INT NOT NULL AUTO_INCREMENT;
DON'T have a field that does that? NO PROBLEM! Use this code below in mysql. If your not on MySQL then look up what it's equililant is.
ALTER TABLE table_name ADD users_id INT NOT NULL AUTO_INCREMENT, ADD primary key(users_id)
That is assuming you don't have any conflicting primary keys. If you do then just igore the primary key part. What this will do is take all your users rows and give them all numbers. Pretty nifty eh? Then how you look up their username (and password I am assuming) you just do another little
$_SESSION['GLOBAL_ID'] = "THEIR ID #";
And your all set. Then call either $GLOBAL_ID or $username. 🙂 Either way will be just fine. Also please note that all session variables become GLOBAL variables. Meaning as long as there is a session_start(); In there then whatever session variables you have set will become active variables. Any questions feel free to hit me back. I don't think I explained it all that well. Thanks so much and have a great day!!
Chad R. Smith