【发布时间】: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
从任何页面,打印店徽标(保存在<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