3

プロジェクトの認証プラグインとしてsfGuardを使用しています。セッションタイムアウト時に特定のクライアント側とサーバー側のスクリプトを呼び出したい。私がこれを行うことができる最善の方法は何ですか。

助けてください!どうもありがとう。

4

1 に答える 1

2

よく読んでいて、ユーザー認証、プロファイル、資格情報などを処理sfGuardSecurityUserするクラスを拡張します。sfBasicSecurityUser

sfBasicSecurityUserそのため、ユーザー セッションが時間指定されているかどうかを判断する関数を で見つけましisTimedOutsetTimedOut

少なくともサーバー側でユーザーのセッションがタイムアウトしたときに何かをしたい場合は、これが発生したときにスローされるイベントをリッスンする必要があります。この方法を確認してください:

これは、symfony_core_root_dir/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'] = 1800;
    }

    // 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']);
    }

    // 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();
  }

クライアント側では、 HTML 5 と Javascript Workersについて考え始めるかもしれません。アイデアは、ページの読み込み時にワーカーを設定し、 までカウントすることを伝えてsession_time_outから、ログインページなどにリダイレクトすることです。

于 2010-12-30T02:08:13.533 に答える