2011-08-05 6 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의 보안 구성 요소는 매우 혼란 스럽습니다. 따라서이 문제를 해결할 수있는 최상의 솔루션을 찾고 있습니다.

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