2011-08-05 19 views
1

CakePHP 1.3を使用して、我々はホテルの部屋の予約システムを持っています。チェックアベイラビリティフォームでは、ユーザーを安全な支払いページ(https://secure.domain.com/bookings/payment)に移動させる必要があります。支払い後、確認ページが表示されますが、ここからヘッダー/フッターのリンクをクリックすると、ユーザーは非セキュアドメイン(http://domain.com)に戻ります。CakePHP HTTPS安全な支払いフォーム

現在、ドメインhttps://secure.domain.comhttps://domain.comに対してSSL UCC証明書が設定されています。また、チェックイン・アベイラビリティ・フォームをハードコード化して、アクションhttps://secure.domain.com/bookings/paymentを実行しました。したがって、HTTPSのセキュリティ保護された領域に入ることができますが、そのセクションにすべてのリンクをハードコードしない限り、バックアウトすることはできません。

ケーキのセキュリティコンポーネントはかなり混乱しています。このため、私はこれを実現する最適なソリューションを探しています。

CakeのセキュリティコンポーネントをHTTPS支払いページに使用できるようになり、生活が楽になり、CakePHPが標準化されます。その他の提案はありますか?

答えて

0

http://techno-geeks.org/2009/03/using-the-security-component-in-cakephp-for-ssl/の例を使用しましたが、問題があることがわかりました。私はapp_controller.phpに以下を追加しました。

次のコードは、HTTPSをwww.example.comに、HTTPをexample.comにリダイレクトします。ユーザーがログインしている場合($loggedUser参照)、すべての接続に対してHTTPSが強制的に実行されます。

// Pages requiring a secure connection. 
$secureItems = array(); 

// beforeFilter 
function beforeFilter() { 
    // Your logic...  
    $this->__checkSSL(); 
} 

/** 
* Check SSL connection. 
*/ 
function __checkSSL() { 
    /** Make sure we are secure when we need to be! **/ 
    if (empty($this->loggedUser)) { 
     if (in_array($this->action, $this->secureItems) && !env('HTTPS')) { 
      $this->__forceSSL(); 
     } 

     if (!in_array($this->action, $this->secureItems) && env('HTTPS')) { 
      $this->__unforceSSL(); 
     } 
    } else { 
     // Always force HTTPS if user is logged in. 
     if (!env('HTTPS')) { 
      $this->__forceSSL(); 
     } 
    } 
} 

/** 
* Redirect to a secure connection 
* @return unknown_type 
*/ 
function __forceSSL() { 
    if (strstr(env('SERVER_NAME'), 'www.')) { 
     $this->redirect('https://' . env('SERVER_NAME') . $this->here); 
    } else { 
     $this->redirect('https://www.' . env('SERVER_NAME') . $this->here); 
    } 
} 

/** 
* Redirect to an unsecure connection 
* @return unknown_type 
*/ 
function __unforceSSL() { 
    if (strstr(env('SERVER_NAME'), 'www.')) { 
     $server = substr(env('SERVER_NAME'), 4); 
     $this->redirect('http://' . $server . $this->here); 
    } else { 
     $this->redirect('http://' . env('SERVER_NAME') . $this->here); 
    } 
}