Avatar of userTester
userTester
Flag for United States of America asked on

PHP MVC and setting Session variable

Hi there,

After validating a user's email and password, where should the user's session variable be set, in the Controller or can it be set in the View? Does it matter where it is set?

Thanks,
Mark
PHPWeb DevelopmentWeb ApplicationsWeb FrameworksWeb Languages and Standards

Avatar of undefined
Last Comment
userTester

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Marco Gasi

As MVC I use CodeIgniter, so I don't know if this can be true for your specific environment, but I usually set session values from the controller. It is possible to do it even in view but the correct way is to keep code in controller (as keeping database stuff in models).
In the controller, you can use standard php $_SESSION array or, it it exists, your framework session class.
userTester

ASKER
Thank you Ray, you provided valuable extra information with that link. Thanks to you too Marco, you basically confirmed what Ray had mentioned.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck