判断http还是https,以及获得当前url的方法

$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
echo $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
	/**
     * PHP判断当前协议是否为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;
	}

  

    $http_type = $this->is_https();
    if($http_type){
    	echo "是https";
    }else{
    	
    	echo "是http";
    }

  

js判断http请求还是https请求

var ishttps = 'https:' == document.location.protocol ? true: false;
if(ishttps){
alert('https');
}else{
alert('http');
}
 

  

posted @ 2019-03-19 10:51  风79  阅读(3333)  评论(0编辑  收藏  举报