2011/12/22

PHP 判斷目前連線是 http 或 https

利用伺服器參數 $_SERVER['HTTPS'] 判斷
$protocol = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
    $protocol = 'https';
}
精簡寫法:
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http";