php-mvc-framework icon indicating copy to clipboard operation
php-mvc-framework copied to clipboard

How can I exclude a form from the session?

Open RobertoVasquez01 opened this issue 3 years ago • 7 comments

I would like to load the CONTACT form and others, without creating an instance of the Session class. Does anyone have a good idea? Help please @thecodeholic!

RobertoVasquez01 avatar Feb 21 '22 05:02 RobertoVasquez01

Please help!

RobertoVasquez01 avatar Feb 28 '22 16:02 RobertoVasquez01

Sorry my friend your requirement is not very clear: and others - What do you mean in others? Why don't you want to create instance of Session class? Can you provide more details?

thecodeholic avatar Feb 28 '22 16:02 thecodeholic

Thanks for your reply. I was not very clear, I hope I am. Maybe I'm wrong because of the lack of experience in app development. But it seems to me that as long as a user does not identify himself in a web application, with his Username and Password, a session should not be created, session_start(). In this way. I suggest that some forms like CONTACT, LOGIN AND OTHERS, DO NOT use session_start().

In the framework, all ROUTEs create an instance of the Session.php Class and a session, session_start(), is also created.

For this reason I assumed that I shouldn't instantiate the Session.php class in some routes, but I'm really not sure about this solution. Any ideas from @thecodeholic creator, will be good, I appreciate it.

RobertoVasquez01 avatar Feb 28 '22 22:02 RobertoVasquez01

Hello!. Does anyone have a good idea?

RobertoVasquez01 avatar Mar 21 '22 07:03 RobertoVasquez01

Hello, IMO you are half right, half wrong. Technically you can skip session initialization, but why? what is the reason of not initializing session? Session can be used not only when user is authorized, but saving some preferences of the user. For example when user opens the site we might detect user's location based on IP address and save that in session, so that we don't have to detect every time user opens the page.

Complex and popular frameworks might have option not to initialize Session instance when not using and this can be implemented here as well, but you can to alter the core of this framework, which IMO is not necessary for this reason. Initializing session does not change anything.

thecodeholic avatar Mar 29 '22 06:03 thecodeholic

Thank you very much. It has been of great help because it confirmed what was investigated. I will use the session to save the preferences of the users, visitors and authorized.

Thank you again.

RobertoVasquez01 avatar Mar 31 '22 04:03 RobertoVasquez01

I have a question. If I use session to save some user preferences. Within my session management, when should I totally destroy the session?

RobertoVasquez01 avatar Apr 02 '22 01:04 RobertoVasquez01