- Broken images
- Missing emoticons such as shopping cart
- After pressing F12 for the developer console, CORS errors show with message saying missing Access-Control-Allow-Origin
- After pressing F12 for the developer console, errors show with message saying the refuse to use the insecure stylesheet and the resource must be served using HTTPS
This also covers the case where a site is accessible on multiple different URLs. For example, if you have installed a store at http://example.com/ , and the customer types in http://www.example.com/ (note the www.), the same symptoms occurs because http://www.example.com/ can't load AJAX from http://example.com/ due to same origin policy. https://example.com/ and https://www.example.com/ are also broken for the same reason.
I have made a pull request to handle this issue: https://github.com/opencart/opencart/pull/6730
However, as config.php and admin/config.php are generated on installation, it only applies to new installations. For existing store owners, simply copying the following the code for config.php and admin/config.php will fix your broken site, no matter where your site is installed and which URL your customer types (i.e. http://example.com/ , https://example.com/ , http://www.example.com/ , https://www.example.com/ will all work as long as your web server is configured to serve them all).
When copying these files, please take care to keep your database credential, and the storage directory (if you have moved it) untouched.
Code: Select all
<?php
// config.php
// Check if SSL
if (((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1')))) || $_SERVER['SERVER_PORT'] == 443) {
$protocol = 'https://';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
// HTTP
define('HTTP_SERVER', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/');
// HTTPS
define('HTTPS_SERVER', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/');
// DIR
define('DIR_OPENCART', str_replace('\\', '/', __DIR__) . '/');
define('DIR_APPLICATION', DIR_OPENCART . 'catalog/');
define('DIR_SYSTEM', DIR_OPENCART . 'system/');
define('DIR_IMAGE', DIR_OPENCART . 'image/');
define('DIR_STORAGE', DIR_SYSTEM . 'storage/'); // keep this line unchanged if you moved your storage
define('DIR_LANGUAGE', DIR_APPLICATION . 'language/');
define('DIR_TEMPLATE', DIR_APPLICATION . 'view/theme/');
define('DIR_CONFIG', DIR_SYSTEM . 'config/');
define('DIR_CACHE', DIR_STORAGE . 'cache/');
define('DIR_DOWNLOAD', DIR_STORAGE . 'download/');
define('DIR_LOGS', DIR_STORAGE . 'logs/');
define('DIR_MODIFICATION', DIR_STORAGE . 'modification/');
define('DIR_SESSION', DIR_STORAGE . 'session/');
define('DIR_UPLOAD', DIR_STORAGE . 'upload/');
// DB
// keep the below lines unchanged for your database credential
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'opencart');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'opencart');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
Code: Select all
<?php
// admin/config.php
// Check if SSL
if (((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1')))) || $_SERVER['SERVER_PORT'] == 443) {
$protocol = 'https://';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
// HTTP
define('HTTP_SERVER', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/');
define('HTTP_CATALOG', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), '/.\\') . '/');
// HTTPS
define('HTTPS_SERVER', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/');
define('HTTPS_CATALOG', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), '/.\\') . '/');
// DIR
define('DIR_OPENCART', realpath(str_replace('\\', '/', __DIR__ . '/..')) . '/');
define('DIR_APPLICATION', DIR_OPENCART . 'admin/');
define('DIR_SYSTEM', DIR_OPENCART . 'system/');
define('DIR_IMAGE', DIR_OPENCART . 'image/');
define('DIR_STORAGE', DIR_SYSTEM . 'storage/'); // keep this line unchanged if you moved your storage
define('DIR_CATALOG', DIR_OPENCART . 'catalog/');
define('DIR_LANGUAGE', DIR_APPLICATION . 'language/');
define('DIR_TEMPLATE', DIR_APPLICATION . 'view/template/');
define('DIR_CONFIG', DIR_SYSTEM . 'config/');
define('DIR_CACHE', DIR_STORAGE . 'cache/');
define('DIR_DOWNLOAD', DIR_STORAGE . 'download/');
define('DIR_LOGS', DIR_STORAGE . 'logs/');
define('DIR_MODIFICATION', DIR_STORAGE . 'modification/');
define('DIR_SESSION', DIR_STORAGE . 'session/');
define('DIR_UPLOAD', DIR_STORAGE . 'upload/');
// DB
// keep the below lines unchanged for your database credential
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'opencart');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'opencart');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
// OpenCart API
define('OPENCART_SERVER', 'https://www.opencart.com/');