Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MARCO_1992's avatar

Session based user role after login

Hello everyone!

Is there a way to change the role of a user based on the session variable?

MY PROBLEM: After login i can assign a role to the user. However, after that there is a possibility in my application that the user can navigate to different subprojects. I have solved this by creating a session variable as soon as the user has activated a subproject by pressing a button. Likewise, he can deactivate the subproject via a button. But now I need different roles for a user depending on which subproject is activated.

Is there an elegant solution or should i approach it differently?

Thanks!

0 likes
6 replies
CorvS's avatar

Is there any problem with storing the roles in the database?

MARCO_1992's avatar

No, but how can I change the role while the user is logged in?

CorvS's avatar
CorvS
Best Answer
Level 27

Just assign a different role to him, when the button is clicked. So store the specific role inside the database.

CorvS's avatar

Wow, that was fast. I am glad it worked out. Let me know if you need any more help.

Please or to participate in this conversation.