2011-01-24 4 views
7

특정 보안 폴더 (예 : 서버의 https 폴더와 http 폴더)를 사용하여 보안 페이지를 구현했습니다. 젠드 프레임 워크를 사용하기 시작했으며, 애플리케이션의 일부 (예 : 로그인)가 https를 사용하기를 원합니다. 나는 구글과 심지어 여기에서 찾았지만 이것을 처리하는 방법을 설명하는 것을 찾을 수 없었다. 특정 컨트롤러/동작에 대해 https를 사용할 수 있습니까? 감사. 의 당신이 모듈/컨트롤러/액션 등이 있다고 가정 해 봅시다Zend MVC에서 SSL을 구현하는 방법

:

+1

중복 [방법 - 투 - 수 - sslmod-rewritezend 프레임 워크-MVC-노동 서로를 (HTTP :/부트 스트랩에 추가합니다 :

  class Application_Controllerplugins_Ssl extends Zend_Controller_Plugin_Abstract { public function preDispatch (Zend_Controller_Request_Abstract $request) { $shouldSecureUrl = false; //get the config settings for SSL $options = Application_ServiceManager::getConfig()->ssl; //if config is empty, exit if (!is_object($options)) return; //simpler to use $options = $options->toArray(); //only use it production environment if (APPLICATION_ENV == 'production') { if ( (isset($options['modules'][$request->module]['require_ssl']) && $options['modules'][$request->module]['require_ssl']) || (isset($options['modules'][$request->module][$request->controller]['require_ssl']) && $options['modules'][$request->module][$request->controller]['require_ssl']) || (isset($options['modules'][$request->module][$request->controller][$request->action]['require_ssl']) && $options['modules'][$request->module][$request->controller][$request->action]['require_ssl']) ) { $shouldSecureUrl = true; } if ($shouldSecureUrl) { $this->_secureUrl($request); } } } protected function _secureUrl (Zend_Controller_Request_Abstract $request) { $server = $request->getServer(); $hostname = $server['HTTP_HOST']; if (! $request->isSecure()) { $url = Zend_Controller_Request_Http::SCHEME_HTTPS . "://" . $hostname . $request->getPathInfo(); $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->setGoToUrl($url); $redirector->redirectAndExit(); } } }  

나는 얘기를 깜빡 했네요 /stackoverflow.com/questions/380050/how-to-get-sslmod-rewritezend-framework-mvc-working-together) – criticus

답변

13

가장 깨끗한 방법은, 모델/컨트롤러/액션 레벨에 대한 SSL 지원을 사용하므로 같은 수의 SSL 설정에 대한 .ini 파일을하는 것입니다 이 :
SSLModule-> IndexController-> testAction는

 

## ini file (can be config.ini also) 
ssl.modules.SSLModule.require_ssl = true //-> entire module requires SSL 
ssl.modules.SSLModule.Index.require_ssl = true //-> entire controller requires SSL 
ssl.modules.SSLModule.Index.test.require_ssl = true //-> single action requires SSL 
 

당신도 설정을 통해이 문제를 분석하거나, 개별적으로, 그리고 부트 스트랩 파일에 여기 내처럼 controllerplugin를 포함 할 수 있습니다.

이 작업을 수행하는 여러 가지 방법이 있지만 아이디어를 얻은 것 같습니다.

 

$Zend_Controller_Front->registerPlugin(new Application_Controllerplugins_Ssl()); 
 
+3

매력처럼 작동합니다. 고마워, 귀중한 공헌. – jgnasser

관련 문제