脚本宝典收集整理的这篇文章主要介绍了php – 如何在Zend MVC中实现SSL,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
假设您有一个模块/控制器/动作,如下所示:
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
你可以通过配置或单独解析它,在你的Bootstrap文件中你可以包含一个controllerplugin,就像我的一样.
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(); } } }
$Zend_Controller_Front->registerPlugin( new Application_Controllerplugins_Ssl() );
以上是脚本宝典为你收集整理的php – 如何在Zend MVC中实现SSL全部内容,希望文章能够帮你解决php – 如何在Zend MVC中实现SSL所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。