php 判断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']; ?>
1、php判断http请求还是https请求

    /**
     * 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;
    }
 

调用:

 
  1. $http_type = $this->is_https();

  2. if($http_type){

  3. echo "是https";

  4. }else{

  5.  
  6. echo "是http";

  7. }

 

 

2、 js判断http请求还是https请求

 
  1. var ishttps = 'https:' == document.location.protocol ? true: false;

  2. if(ishttps){

  3. alert('https');

  4. }else{

  5. alert('http');

  6. }

来源:https://blog.csdn.net/haibo0668/article/details/81113133

转载:https://blog.csdn.net/ghostyusheng/article/details/53581825

https://blog.csdn.net/u010073893/article/details/53639218#

你可能感兴趣的:(php,https/http)