Join David Powers for an in-depth discussion in this video Destroying the session, part of Managing PHP Persistent Sessions.
- The final method of the session handler interface…that we need to define is destroy.…Its role is to remove from the server…everything related with the session…and it's called internally by PHP…when you invoke the session destroy function.…The signature for the destroy method is on line 236.…It takes a single parameter, the session_id…which it gets automatically when session destroy is called.…I've got the code for the destroy method…in this file destroy.txt…which you can find in the exercise files for this video.…
Just select everything, copy it,…and back to MysqlSessionHandler.php…and paste it inside the destroy method.…The code is fairly simple,…it's an sql delete statement…DELETE FROM the session table…where the sid column equals sid.…And this is a named parameter.…Inside the try block we create a prepared statement…using that sql and then bind the session_id,…the sid named parameter and execute.…
If anything goes wrong PDO will throw an exception.…It's caught in the catch block.…If we're inside the transaction, we roll back…
- Configuring sessions
- Inspecting how session data is stored
- Implementing persistent sessions
- Creating a SQL database to store session data
- Implementing the PHP SessionHandlerInterface
- Writing session data
- Closing and destroying sessions
- Creating an auto-login system with persistent sessions
- Creating persistent logins
- Checking out visitor credentials
- Authenticating users
- Logging out users selectively
Skill Level Intermediate
Accessing Databases with Object-Oriented PHPwith David Powers3h 47m Intermediate
1. Sessions and Security
2. Preparing the Database
Connecting to the database5m 49s
3. Storing Session Data in MySQL
4. Creating an Autologin System
5. Testing the Autologin System
Final thoughts3m 9s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.