You donโt think too much about it ... thinking is good!
I personally use symfony 1.4 for coding that solves such problems, but you can opt out of lean :-)
I would think OO (Object Oriented). Create a user class. Then make calls such as UserFactory :: getCurrentUser () or User :: getCurrentUser (), which will return the currently registered user object. Among the member variables of this class will be user_id. However, you can add add functionality and data to this class.
Remember that thinking in OO means using abstract terms that are very close to a problem area. User, car, order, etc. You do not have to be specific, and you do not need to include all the available information in this class so that it is "complete", whatever that is. Include only the data you need at the moment (hold yagni ). Classes are illusions of concrete, real things. Just like 3D modeling is an illusion of the real world.
Hope this helps ...
Homer6
source share