Is there currently - or has there ever been - any serious or significant problem with PHP's built-in session handling?
I mean, it's always worked for me and my projects.
But I see some codebases and frameworks out there seem to use a custom handler. Is this reinventing the wheel? Or improving on some flaws? What flaws?
State is essential is some circumstances, and PHP's sessions is a good startpoint for most applications. As a learner, start with that, and when your needs dictate other means, learn about that.
A PHP session is easily started by making a call to the session_start() function. This function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.
PHP provides a cookie-based implementation for session management. The $_SESSION array is used for storing session data. PHP automatically generates a session ID and sends a session cookie containing this session ID to the client machine.
Start a PHP SessionA session is started with the session_start() function. Session variables are set with the PHP global variable: $_SESSION.
Pros:
session_start()
and you're done)Cons:
Pros:
Cons:
Is there currently - or has there ever been - any serious or significant problem with PHP's built-in session handling?
No problems with the built-in handlers. Access and deletion of old session files are implemented well.
Is this reinventing the wheel? Or improving on some flaws? What flaws?
File based session handling works fine for single server websites. Problems may arise when applications need to be run on multiple servers (scaled out). A master database can be used to store and provide session information across multiple servers. This can make things easier when an application is scaled out. Custom session handlers can be used to interact with the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With