[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/session/src/Validator/ -> ForwardedValidator.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Session Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Session\Validator;
  10  
  11  use Joomla\Input\Input;
  12  use Joomla\Session\SessionInterface;
  13  use Joomla\Session\ValidatorInterface;
  14  
  15  /**
  16   * Interface for validating a part of the session
  17   *
  18   * @since  2.0.0
  19   */
  20  class ForwardedValidator implements ValidatorInterface
  21  {
  22      /**
  23       * The Input object.
  24       *
  25       * @var    Input
  26       * @since  2.0.0
  27       */
  28      private $input;
  29  
  30      /**
  31       * The session object.
  32       *
  33       * @var    SessionInterface
  34       * @since  2.0.0
  35       */
  36      private $session;
  37  
  38      /**
  39       * Constructor
  40       *
  41       * @param   Input             $input    The input object
  42       * @param   SessionInterface  $session  DispatcherInterface for the session to use.
  43       *
  44       * @since   2.0.0
  45       */
  46  	public function __construct(Input $input, SessionInterface $session)
  47      {
  48          $this->input   = $input;
  49          $this->session = $session;
  50      }
  51  
  52      /**
  53       * Validates the session
  54       *
  55       * @param   boolean  $restart  Flag if the session should be restarted
  56       *
  57       * @return  void
  58       *
  59       * @since   2.0.0
  60       */
  61  	public function validate(bool $restart = false): void
  62      {
  63          if ($restart)
  64          {
  65              $this->session->set('session.client.forwarded', null);
  66          }
  67  
  68          $xForwardedFor = $this->input->server->getString('HTTP_X_FORWARDED_FOR', '');
  69  
  70          // Record proxy forwarded for in the session in case we need it later
  71          if (!empty($xForwardedFor) && filter_var($xForwardedFor, FILTER_VALIDATE_IP) !== false)
  72          {
  73              $this->session->set('session.client.forwarded', $xForwardedFor);
  74          }
  75      }
  76  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer