HttpUserAgent.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Session
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. * @since Preview Release 0.2
  21. */
  22. /**
  23. * @see Zend_Session_Validator_Abstract
  24. */
  25. require_once 'Zend/Session/Validator/Abstract.php';
  26. /**
  27. * Zend_Session_Validator_HttpUserAgent
  28. *
  29. * @category Zend
  30. * @package Zend_Session
  31. * @subpackage Validator
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Session_Validator_HttpUserAgent extends Zend_Session_Validator_Abstract
  36. {
  37. /**
  38. * Setup() - this method will get the current user agent and store it in the session
  39. * as 'valid data'
  40. *
  41. * @return void
  42. */
  43. public function setup()
  44. {
  45. $this->setValidData( (isset($_SERVER['HTTP_USER_AGENT'])
  46. ? $_SERVER['HTTP_USER_AGENT'] : null) );
  47. }
  48. /**
  49. * Validate() - this method will determine if the current user agent matches the
  50. * user agent we stored when we initialized this variable.
  51. *
  52. * @return bool
  53. */
  54. public function validate()
  55. {
  56. $currentBrowser = (isset($_SERVER['HTTP_USER_AGENT'])
  57. ? $_SERVER['HTTP_USER_AGENT'] : null);
  58. return $currentBrowser === $this->getValidData();
  59. }
  60. }