paulc8481 Posted April 9, 2012 Share Posted April 9, 2012 I am new to php and would like help understanding Sessions and session variables. When should I or should I not make my php, sessions? I have this Idea that by creating all my documents sessions It will always be easier to reuse all my session variables in other documents. Is this ok or is there a way to use variable in other documents without making a session? I want to code correctly and professionally but I don,t want to become a creature of BAD HABIT. Quote Link to comment https://forums.phpfreaks.com/topic/260630-reusing-variable/ Share on other sites More sharing options...
Psycho Posted April 9, 2012 Share Posted April 9, 2012 Whether a value should be stored in a session or not is dependent on many factors. If the data needs to persists across sessions, then you will likely want to store it in a cookie or in a database. Typical things to store in a session are data to indicate that the user is logged in, shopping cart data, some preferences, etc. It's really hard to give you an answer without knowing what the variable is used for. Quote Link to comment https://forums.phpfreaks.com/topic/260630-reusing-variable/#findComment-1335765 Share on other sites More sharing options...
paulc8481 Posted April 9, 2012 Author Share Posted April 9, 2012 The type of variables would be things such as an address, a job position, if a person has paid their membership dues, something that may need to be calculated, etc etc. Quote Link to comment https://forums.phpfreaks.com/topic/260630-reusing-variable/#findComment-1335769 Share on other sites More sharing options...
scootstah Posted April 9, 2012 Share Posted April 9, 2012 You shouldn't store all of that in a session. What you can do, though, is save the user's ID to a session. Then whenever you want to look up the user's information you can just fetch it from the database, since you know their ID. Quote Link to comment https://forums.phpfreaks.com/topic/260630-reusing-variable/#findComment-1335771 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.