【问题标题】:Making OpenCart 2.2 Installation 100% HTTPS使 OpenCart 2.2 安装 100% HTTPS
【发布时间】:2016-11-12 18:39:16
【问题描述】:

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

从任何页面,打印店徽标(保存在&lt;div id="logo"&gt;)将用户返回到非 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】:

    s,

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

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

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

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

    最后两个参数用于 SSL。

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

    默认 $secure 参数为 false

    您将设置默认 $secure 参数 = true 或设置控制器文件的最后一个参数。

    希望这会对你有所帮助。

    【讨论】:

    • 感谢@Vipul Jethva。我已经按照建议编辑了 url.php 文件,这似乎解决了一些问题,但是如果我转到管理员登录页面,即使转到 oracle101.co.uk/printshop/admin/index.php?route=common/login,表单操作仍然指向 http 而不是 https。我需要在这里编辑一些东西吗:admin/controller/common/login.php 我能看到的只是$data['action'] = $this-&gt;url-&gt;link('common/login', '', true);,它已经设置为true,不是吗?谢谢
    • 您将在系统 -> 图书馆-> url 上创建 https。仅当条件具有 https。所以你也会在 else 条件下创建 https。
    猜你喜欢
    • 2016-09-03
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2014-01-15
    相关资源
    最近更新 更多