编程语言
首页 > 编程语言> > php-在某些页面上但并非在所有页面上都使用https请求zend framework

php-在某些页面上但并非在所有页面上都使用https请求zend framework

作者:互联网

我需要将https放在某些URL上,而不是放在所有URL上.我正在为所有链接使用zend URl视图助手.我有整个网站的* .example.com SSL证书.现在,我用https://www.example.co打开网站,然后主页或其他页面上的所有链接在URL中都包含https.我如何在https url上发出一些特定请求,而其他页面应该正常打开.

我还需要进行一些重定向,以便如果有人使用常规URL打开特定页面,则它们将重定向到https url.我认为.htaccess重定向将对此有效.

有帮助吗????

提前致谢!!!

解决方法:

URL ViewHelper仅组装从主机名绝对的路径.因此,您需要明确为https链接添加前缀

<? $url = $view->url(array('some' => 'params') /*, $route, $reset*/) ?>
<a href="https://<?= $_SERVER['HTTP_HOST] ?><?= $url ?>">my explicit https link</a>

您可能应该创建一个自己的小型viewhelper,它可以为您工作,还可以检查是否设置了HTTP_HOST等,也可以从配置中获取,而不是从$_SERVER获取.

$view->httpsUrl(array(‘some’ => ‘params’)/, $route, $reset/);

为了确保已定义的需求必须为https,可以通过添加前端控制器插件或您基于所有otehr控制器的抽象控制器类轻松完成.

一个插件可能看起来像这样

My_Controller_Plugin_HttpBlacklist extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        // when /foo/bar/baz is requested
        if (($request->getModuleName() == 'foo' &&
            $request->getControllerName() == 'bar' &&
            $request->getControllerName() == 'baz')
            /* || (conditions for more requests)*/) {

            //very basic confifiotn to see if https is enabled, should be done better...
            if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') {

                // should be done with Zend_Http_Reponse instead
                header('Location: https://'. $_SERVER['HTTP_HOST] . $_SERVER['REQUEST_URI']);
                exit;
            }
        }
    }
}

然后简单地插入

$frontController->registerPlugin(new My_Controller_Plugin_HttpBlacklist);

标签:zend-framework,php
来源: https://codeday.me/bug/20191209/2096510.html