使OpenCart 2.2安装100%HTTPS

问题描述 投票:0回答:1

我今天刚刚在我的网站上安装了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。

opencart opencart2.x
1个回答
2
投票

s,

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

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

你需要传递最后两个参数,比如

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

最后两个参数用于SSL。

如果您需要检查代码。然后得到System - > Library - > Url.php文件。

默认$ secure参数为false。

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

希望这会帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.