导读:
如果网站域名使用了SSL安全证书,但没有强制转https的话,https域名调用url()函数时,会出现如下报错:
Mixed Content: The page at 'https://18pay.net/Index/User/vip.html' was loaded over HTTPS, but requested an insecure form action 'http://18pay.net/Index/Pay/page.html'. This request has been blocked; the content must be served over HTTPS.
解决方案:
方法一、在config.php配置文件里添加以下配置项:
'is_https' => true,//是否开启https false不开启则生产http的URL
方法二:直接修改Thinkphp框架文件,thinkphp/library/think/Url.php
1、在url.php里添加一个新函数
protected static function isHttps(){
if (defined('HTTPS') && HTTPS){return true;}
if (!isset($_SERVER['HTTPS'])){return false;}
if ($_SERVER['HTTPS'] === 1) { //Apache
return true;
} elseif ($_SERVER['HTTPS'] === 'on') { //IIS
return true;
} elseif ($_SERVER['SERVER_PORT'] == 443) { //其他
return true;
}
return false;
}
2、修改parseDomain(&$url, $domain)函数
把下面这一句代码
$scheme = $request->isSsl() || Config::get('is_https') ? 'https://' : 'http://';
改为:
//$scheme = $request->isSsl() || Config::get('is_https') ? 'https://' : 'http://';
$scheme = $request->isSsl() || self::isHttps() ? 'https://' : 'http://';