If you store a session in a database you have several advantages:
@ Improving the security because on many hosting packages (shared host)
PHP uses the same path for storing sessions for all the users,
somewhere that is not in your folders.
@ You can track who is online etc.
@ For application that are running on multiple servers, you can store
all the session data in one database.
The real beauty of this approach is that you don't have to modify your code or the way you use sessions in any way. $_SESSION still exists and behaves the same way, PHP still takes care of generating and propagating the session identifier, and changes made to session configuration directives still apply. All you have to do is call this one function.
You must call session_set_save_handler() prior to calling session_start(), but you can define the functions themselves anywhere.
The function is called session_set_save_handler(), and it takes six arguments,
1. Opening the session data store
2. Closing the session data store
3. Reading session data
4. Writing session data
5. Destroying all session data
6. Cleaning out old session data
How is it useful when application is hosted on multiple servers
Hi,
I have been working with php and now i'm working with one project that need to be hosted on multiple servers.
So i thought, we might need to store the session in database.
Is it mandatory to store session in database when web application is hosted on multiple servers and application in concerned to load balance ?
A little help is appreciated.
Thanks
Sachin Pethani
Post new comment