php 判断页面或图片是否经过gzip压缩的方法

(编辑:jimmy 日期: 2024/10/2 浏览:2)

使用php判断页面或图片是否经过gzip压缩方法

1.使用get_headers

页面内容

<"htmlcode">
<"color: #ff0000">2.使用curl

图片

<"htmlcode">
<"\r\n", "\r");
  $header_str = str_replace($filter, PHP_EOL, $header_str);

  // 检查content-encoding
  preg_match('/Content-Encoding: (.*)\s/i', $header_str, $matches);
  if(isset($matches[1]) && $matches[1]=='gzip'){
   return true;
  }
 }
 return false;
}
"color: #ff0000">测试结果: 

当加上ob_gzhandler时,返回true,删除后返回false

以上这篇php 判断页面或图片是否经过gzip压缩的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。