我已经编写了一个小函数来建立当前的站点URL协议,但是我没有SSL,也不知道如何测试它是否在https下工作.Can you tell me if this is correct?个
function siteURL()
{
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$domainName = $_SERVER['HTTP_HOST'].'/';
return $protocol.$domainName;
}
define( 'SITE_URL', siteURL() );
Is it necessary to do it like above or can I just do it like?:
function siteURL()
{
$protocol = 'http://';
$domainName = $_SERVER['HTTP_HOST'].'/'
return $protocol.$domainName;
}
define( 'SITE_URL', siteURL() );
在ssl下,即使锚标签url使用http,服务器也不会自动将url转换为https吗?有必要判断协议吗?
谢谢!