PHP判断客户端协议类型是否为https

PHP官方建议方法:

  if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
      echo "是https协议";
  }

带转发的情况下:

$protocol = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || 
                     (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https : 'http';

你可能感兴趣的:(PHP判断客户端协议类型是否为https)