#### 1. PHP 判斷當前協(xié)議是否為 HTTPS --- ```php /** * 判斷當前協(xié)議是否為 HTTPS */ function is_https() { if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { return true; } elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) { return true; } elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { return true; } return false; } ``` #### 2. PHP 獲取包含網(wǎng)址協(xié)議的當前域名 --- ```php echo domain();//http://waterflosserreview.com ``` ```php /** * 獲取包含網(wǎng)址協(xié)議的域名 */ function domain() { $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http'; return $http_type . '://' . $_SERVER['HTTP_HOST']; } ``` #### 3. JavaScript 判斷當前協(xié)議是否為 HTTPS --- ```javascript function is_https() { return 'https:' == location.protocol ? true: false; } ``` #### 4. JavaScript 獲取包含網(wǎng)址協(xié)議的當前域名 --- ```javascript var domain = location.protocol + '//' + location.host ```