2011-01-24 21 views
7

Belirli bir güvenli klasör (örneğin, sunucudaki https klasörü vs http klasörü) kullanarak daha önce güvenli sayfalar uygulayabildim. Zend Framework'ü kullanmaya başladım ve uygulamanın bölümlerini (örneğin giriş) https kullanmasını istiyorum. Google'da arama yaptım ve burayı nasıl ele alacağımı açıklayan bir şey bulamadım. Belirli kontrolörler/eylemler için https alabilir miyim? Teşekkürler. Diyelim ki bir modül/kontrolör/eylem gibi var diyelimZend MVC'de SSL nasıl uygulanır

:

+1

için yinelenen [how-to-get-sslmod-rewritezend-çerçeve-mvc-işçi birlikte] (http:/senin bootstrap içinde eklemek için:

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

şeyi söylemeyi unuttum /stackoverflow.com/questions/380050/how-to-get-sslmod-rewritezend-framework-mvc-working-together) – criticus

cevap

13

en temiz yolu, model/kontrolör/eylem düzeyleri için SSL desteği sağlamak şöyle olabilir SSL yapılandırma için bir .ini dosyası sahip olmaktır Bu:
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 
 

ya yapılandırma ile bu ayrıştırma, ya da ayrı ayrı, ve Bootstrap dosyasında burada benim gibi, bir controllerplugin içerebilir.

Bunu yapmanın başka birçok yolu var, ama bence bu fikri aldınız!

 

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

Bir çekicilik gibi çalıştım. Çok teşekkürler, çok değerli katkı. – jgnasser