【发布时间】:2011-11-01 06:53:02
【问题描述】:
我希望对我在页面中链接的资源进行 https/http 的“智能”检测。基本上如果页面需要有效的ssl,我只能放httpshref的。
选项 1(使用 PHP)
<?php
if ( $_SERVER["SERVER_PORT"] == "80" ) {
$http = "http";
} else {
$http = "https";
}
?>
<script type="text/javascript" src="<?=$http?>://myUri.com/script.js"></script>
选项 2(使用 // 而不是 http:// OR https://)
<script type="text/javascript" src="//myUri.com/script.js"></script>
选项 3 使用 https 适用于一切
有什么理由我不应该只使用 https 吗?
【问题讨论】:
-
关于“我有什么理由不应该对所有事情都使用 https 吗?”一方面它要慢得多。