Skip to content

Latest commit

 

History

History
54 lines (44 loc) · 1.53 KB

Session Validators.md

File metadata and controls

54 lines (44 loc) · 1.53 KB

Session Validators

Session validators provide various protection against session hijacking. Please view this one first.

Using Session Validators

That is pretty easy.

return [
    'htsession' => [
        'options' => [
            'validators' => [
                // validators list goes here
            ]        
        ]
    ]
];

Zend Framework 2 comes with 2 session validators:

  1. Zend\Session\Validator\RemoteAddr
  2. Zend\Session\Validator\HttpUserAgent

Creating custom session validators

To create a custom role providers, you first need to create a class that implements the Zend\Session\Validator\ValidatorInterface interface.

Then, you need to add it to the session validator plugin manager this way:

return [
    'htsession' => [
        'validators' => [
            'factories' => [
                'Application\Session\Validator\MySessionValidator' => `Application\Factory\MySessionValidatorFactory`
            ]
        ]
    ]
];

Now, your session validator is only added to the session validator plugin manager. To use this:

return [
    'htsession' => [
        'options' => [
            'validators' => [
                'Application\Session\Validator\MySessionValidator'
            ]        
        ]
    ]
];