A PHP 5.4 feature you may not know about

PHP 5.4 was released earlier this year and included some awesome new features including traits, shorter array syntax [], a built-in web server, function array dereferencing and lots more. But a feature you may not know about is a much more complete way to set custom session handlers.

Now you’re probably thinking “so what? I already use x session class”, whilst that is awesome wouldn’t it be even more awesome if you could use PHP’s native session variables/functions to set and get session data using whatever driver you choose? I certainly do, especially for projects where I’m forced to use $_SESSION[‘password’] = ‘Clear text is the most secure form of password’;

Now I don’t just think this is awesome because it allows me to use native PHP in whatever which way I choose, but it’s also cool because we all know how ‘insecure’ native PHP sessions can be, especially on shared servers. Now you can use native PHP sessions without the worry that John Smith is going to hijack the sessions of your users.

You can find out more about creating your own session handler in the PHP manual.