【问题标题】:OrangeHRM auto logout issueOrangeHRM 自动注销问题
【发布时间】:2016-05-11 16:21:22
【问题描述】:

我遇到了使用 Symfony 1.2.4 构建的 OrangeHRM 的自动注销问题

我尝试了什么?

  1. 我已尝试通过php.ini.htaccess 为SESSIONS 分配最大时间

  2. 在评论文件/symfony/lib/vendor/symfony/lib/user/sfBasicSecurityUser.class.php的以下代码后尝试

    public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
    {
    // initialize parent
    parent::initialize($dispatcher, $storage, $options);
    
    if (!array_key_exists('timeout', $this->options))
    {
      $this->options['timeout'] = 86400;
      //$this->options['timeout'] = 1800;
    }
    
    
    $this->options['timeout'] = 86400;
    //$this->options['timeout'] = 2 * 24 * 60 * 60;
    
    // force the max lifetime for session garbage collector to be greater than timeout
    /*if (ini_get('session.gc_maxlifetime') < $this->options['timeout'])
    {
      ini_set('session.gc_maxlifetime', $this->options['timeout']);
    }*/
    ini_set('session.gc_maxlifetime', $this->options['timeout']);
    
    // read data from storage
    $this->authenticated = $storage->read(self::AUTH_NAMESPACE);
    $this->credentials   = $storage->read(self::CREDENTIAL_NAMESPACE);
    $this->lastRequest   = $storage->read(self::LAST_REQUEST_NAMESPACE);
    
    if (null === $this->authenticated)
    {
      $this->authenticated = false;
      $this->credentials   = array();
    }
    else
    {
      // Automatic logout logged in user if no request within timeout parameter seconds
      $timeout = $this->options['timeout'];
      if (false !== $timeout && null !== $this->lastRequest && time() - $this->lastRequest >= $timeout)
      {
        if ($this->options['logging'])
        {
          $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Automatic user logout due to timeout')));
        }
    
        $this->setTimedOut();
        $this->setAuthenticated(false);
      }
    }
    
    $this->lastRequest = time();
    

    }

  3. 尝试手动设置$_SESSION['symfony/user/sfUser/lastRequest']

  4. 尝试通过AJAX 发送获取请求来保持活动状态。

  5. 试图从位于.../symfony/apps/orangehrm/config/factories.ymlYML 设置文件增加会话时间

    all:
      routing:
        class: sfPatternRouting
        param:
          generate_shortest_url:            true
          extra_parameters_as_query_string: true
      storage:
        class: sfSessionStorage
        param:
          session_name: PHPSESSID
          session_cache_limiter: nocache
      user:
         class: myUser
         param:
           timeout:         86000
           logging:         %SF_LOGGING_ENABLED%
           use_flash:       true
           default_culture: %SF_DEFAULT_CULTURE%
    

最终结果

以上所有技术都失败了。

【问题讨论】:

    标签: php orangehrm symfony-1.2


    【解决方案1】:

    首先,您不应该触摸供应商目录中的文件!

    在 symfony 应用程序中修改会话生命周期的正确方法是通过 config.yml 文件。 See this question for reference.

    【讨论】:

    • 您好,感谢您的回复。我已经尝试过您提供的解决方案,但仍然遇到问题。
    • 我的 symfony 版本是1.2.4
    【解决方案2】:

    尽管这有点晚了,但这将帮助您延长会话超时值。此设置位于.../symfony/apps/orangehrm/config/factories.yml 文件中。

    你会看到下面的设置,

    all:
      routing:
        class: ohrmPatternRouting
        param:
          generate_shortest_url:            true
          extra_parameters_as_query_string: true
      storage:
        class: sfSessionStorage
        param:
          session_name: PHPSESSID
          session_cookie_secure: true
          session_cache_limiter: nocache
      user:
         class: myUser
         param:
           timeout:         1800 #change this value to change the session timeout interval
           logging:         %SF_LOGGING_ENABLED%
           use_flash:       true
           default_culture: %SF_DEFAULT_CULTURE%
    

    您应该更改的相关值是timeout 参数。默认值为 1800 秒(30 分钟)。如果您在开发环境中,请执行 symfony clear cache 命令(在终端中进入symfony 文件夹并执行./symfony cc)以使其工作。希望这会有所帮助!

    【讨论】:

    • 感谢您的回复。我已经尝试过这个但失败了。请再次查看我的更新答案。
    猜你喜欢
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 2011-01-05
    相关资源
    最近更新 更多