AmySession::authorize PHP Method

authorize() public method

public authorize ( )
    public function authorize()
    {
        AmyLogger::logn('Authorizing session, cookie token value:', $_COOKIE['amy_token']);
        if (!isset($_COOKIE['amy_token']) || '32' != strlen($_COOKIE['amy_token'])) {
            AmyLogger::logn('Invalid or non-existent session token.');
            throw new Exception('Invalid or non-existent session token.');
        }
        $session_path = $this->session_storage_path . $_COOKIE['amy_token'];
        if (!@file_exists($session_path)) {
            AmyLogger::logn("Unable to authorize session: `session file not found at {$session_path}'.");
            throw new Exception("Unable to authorize session: `session file not found'.");
        }
        $this->authInfo = @unserialize(@file_get_contents($session_path));
        if (!is_array($this->authInfo)) {
            AmyLogger::logn("Unable to authorize session: `session file corrupted or could not been read at {$session_path}'.");
            throw new Exception("Unable to authorize session: `session file unreadable or corupted'.");
        }
        AmyLogger::logn("Session authorized.", $this->authInfo);
        return $this;
    }

Usage Example

Beispiel #1
0
 public function __construct($configuration = array())
 {
     $this->configuration = $configuration;
     $this->configuration['original-support-path'] = $this->configuration['support-path'];
     try {
         $session = new AmySession($configuration);
         $session->authorize();
         $this->user = new AmyUser($configuration);
         $this->user->load_from_session($session);
     } catch (Exception $e) {
         // echo $e->getMessage();
     }
     try {
         if (null === $this->user) {
             $this->user = new AmyUser($configuration);
             $this->user->make_default();
             $this->user->create_session();
         }
         $this->configuration['support-path'] .= '/' . $this->user->service . '_' . $this->user->username . '/';
     } catch (Exception $e) {
         $this->configuration['support-path'] .= '/amy_default/';
     }
 }
All Usage Examples Of AmySession::authorize