使OpenCart 2.2安装100%HTTPS

时间:2016-07-10 20:53:23

标签: opencart opencart2.x

我刚刚在我的网站上安装了OpenCart 2.2,在Apache服务器上运行,运行PHP 7.0.8版。

网站已安装SSL证书,我可以通过以下方式访问购物目录:

https://example.com/printshop/index.php

我希望整个设置在SSL上运行,因此我编辑了相关的配置文件,如下所示:

https://example.com/printshop/config.php

// HTTP
define('HTTP_SERVER', 'https://example.com/printshop/');

// HTTPS
define('HTTPS_SERVER', 'https://example.com/printshop/');

https://example.com/printshop/admin/config.php

// HTTP
define('HTTP_SERVER', 'https://example.com/printshop/admin/');
define('HTTP_CATALOG', 'https://example.com/printshop/');

// HTTPS
define('HTTPS_SERVER', 'https://example.com/printshop/admin/');
define('HTTPS_CATALOG', 'https://example.com/printshop/');

我遇到的问题是页面不是100%安全的,因为表单操作指向一个不安全的URL - 例如

<form action="http://example.com/printshop/index.php?route=common/currency/currency" method="post" enctype="multipart/form-data" id="form-currency">

这同样适用于登录表单(即它的操作指向http而不是https):

https://example.com/printshop/admin/index.php?route=common/login

从任何页面,印刷店徽标(在<div id="logo">中保存)都会将用户返回到非HTTPS页面。

除了像我已经完成的那样更改配置文件中的URL之外,在任何地方都没有允许我设置安装URL的全局设置吗?

已更新以包含解决方案

感谢@Vipul Jethva的建议,我得到了一个解决方案。

编辑/system/library/url.php

更改代码:

public function link($route, $args = '', $secure = false) {
    if ($this->ssl && $secure) {
        $url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
    } else {
        $url = 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
    }
    ...
}

要:

public function link($route, $args = '', $secure = true) {
    if ($this->ssl && $secure) {
        $url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
    } else {
        $url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
    }
    ...
}

另外,请务必更新安装根目录中的config.php,并将admin / config.php更新为指向https。

1 个答案:

答案 0 :(得分:2)

s,

控制器文件上有以下代码。

$this->url->link('common/home');

您需要传递最后两个参数,例如

$this->url->link('common/home','',true);

最后两个参数用于SSL。

如果您需要检查代码。然后得到系统 - &gt;图书馆 - &gt; Url.php文件。

  

默认 $ secure 参数为 false

您将使默认值$ secure parameter = true或在控制器文件上创建最后一个参数。

希望这会对你有所帮助。