Forum Moderators: coopster
Often when I create a user table I create a user_id column as the Primary Key and Auto Increment. Then when I create a member page I normally relate the user to this id.
e.g member.php?id=2 would be the 2nd user entered in the database. Just recently I've been thinking that this might not be the best way to go about it as anyone would know the exact row on the table a user sits on. Am I better not exposing this PK but instead creating another field e.g uid which is in face some kind of hash of the time they regsitered or something unique number? e.g. uniqid(rand()); kind of style?
I notice a lot of the big boys must seem to do something similar as they don't seem to have these incrementing numbers.
Many Thanks
But there are some good reasons not to expose this value. For sites just starting out, you may not want to expose the fact that your user base is small. For many, it's common practice to initialize the starting value at some larger number, say 10000. Then again, for some users it is a point of pride to have a low user ID.
Another reason not to expose the number is for SEO or just having nicer URLs. Instead of /profile.php?memberId=123 you could have /profile/username
What I do is, maintain a separate field in addition to username that is set to a lowercase version of username with spaces stripped out. So if the username is Cool Guy, this other field will be coolguy. And I'd use that as the visible key in a URL like /profile/coolguy