2011-01-24 9 views
7

特定の安全なフォルダ(たとえば、サーバー上のhttpsフォルダとhttpフォルダ)を使用して、安全なページを実装しました。私はZend Frameworkの使用を開始しており、アプリケーションの一部(例えばログイン)にhttpsを使用したいと考えています。私はGoogleとここでも検索していますが、これを処理する方法を説明するものは何も見つかりませんでした。特定のコントローラ/アクションに対してhttpsを使用できますか?ありがとう。あなたはモジュール/コントローラ/アクションなどを持っているとしましょうZend MVCでSSLを実装する方法

+1

の重複[ハウツー-GET-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

関連する問題