我通过使用特定的安全文件夹(例如服务器上的https文件夹vs http文件夹)实现了安全页面。我已经开始使用Zend Framework,并希望部分应用程序(例如登录)使用https。我已经搜索谷歌,甚至在这里,但找不到解释如何处理这个问题。我可以为特定的控制器/操作提供https吗?谢谢。如何在Zend MVC中实现SSL
7
A
回答
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,像我。
还有很多其他方法可以做到这一点,但我认为你明白了!
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());
+3
工作就像一个魅力。非常感谢,非常宝贵的贡献。 – jgnasser 2011-04-26 01:13:17
相关问题
- 1. 如何在symfony 1.4中实现SSL?
- 2. 如何实现MVC在我的Zend框架
- 3. 在java中实现SSL rmi
- 4. 在Java中实现SSL clientAuth
- 5. 如何实现MVC在PHP
- 6. 如何实现MVC
- 7. 如何在asp.net MVC中实现区域?
- 8. 如何在jQuery中实现MVC
- 9. 如何在Tkinter中实现MVC模式
- 10. 如何在ASP.NET MVC中实现角色?
- 11. 如何获得SSL + mod_rewrite + Zend Framework MVC一起工作?
- 12. zend中的ajax实现
- 13. 如何使用Ajax实现Zend路由
- 14. 如何使用Zend实现Facebook Oauth?
- 15. mvc如何在Zend框架中工作
- 16. 在WCF中实现SSL加密
- 17. 在C#中实现SSL隧道#
- 18. 在JSP中实现MVC
- 19. 在php中实现Ajax MVC
- 20. 在asp.net中实现returnurl mvc
- 21. 在MVC中实现验证
- 22. 在iPhone中实现MVC
- 23. Zend Framework:实现Zend_Acl_Resources
- 24. 在zend框架工程中实现cron
- 25. 在Zend模型中实现PostgreSQL数组
- 26. 在ZEND框架中实现SAAS
- 27. 在CodeIgniter中实现Zend Gmail OAuth
- 28. 如何在局域网上实现MVC?
- 29. 如何实现在asp.net的MVC
- 30. 如何在Apache 2.4.18服务器中实现没有ssl的http2
式两份[如何对GET-sslmod-rewritezend框架-MVC-工作在一起(HTTP:/ /stackoverflow.com/questions/380050/how-to-get-sslmod-rewritezend-framework-mvc-working-together) – criticus 2011-03-02 21:41:46