Link to home
Start Free TrialLog in
Avatar of userTester
userTesterFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
Avatar of 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.