Customizing sessions using session_start parameters
Up until PHP 7, in order to override php.ini
settings for secure session management, you had to use a series of ini_set()
commands. This approach is extremely annoying in that you also needed to know which settings were available, and being able to re-use the same settings in other applications was difficult. As of PHP 7, however, you can supply an array of parameters to the session_start()
command, which immediately sets those values.
How to do it...
- We start by developing an
Application\Security\SessOptions
class, which will hold session parameters and also have the ability to start the session. We also define a class constant in case invalid session options are passed:namespace Application\Security; ...
Get PHP 7: Real World Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.