php判断当前是http还是https
php判断当前是http还是https,使用 $_SERVER['HTTPS'] 的值来判断,或者通过 $_SERVER['SERVER_PORT'] 的端口号443来判断是否是https,如果is_ssl()方法返回true则是https,如果返回false则是http。
/** * 判断是否SSL协议 * @return boolean */ function is_ssl() { if(isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))){ return true; }else if(isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'] )) { return true; } return false; }
使用:
$http = 'http://'; $http =is_ssl() ? 'https://' : $http;