php etags

发布时间:2021-07-16 17:07:58 阅读:1107次

 http://www.web-tinker.com/article/20075.html
<?php
ob_start();

//此处是页面的代码
//这里用当前分钟数做测试
#echo time();
echo "hello the world!";
include "conn.php";
$db=mysql_select_db("aabb");
$sql="select *from v9_news limit 100";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
print_r($row);
}

//读取ob缓冲区的所有数据
$s=ob_get_contents();
//关闭ob,并清空缓冲区
ob_end_clean();
//生成ETag
$ETag=md5($s);
//判断客户端请求的ETag是否和当前页面的ETag相同
if($_SERVER['HTTP_IF_NONE_MATCH']==$ETag){
  //如果相同则返回304状态码
  header('HTTP/1.1 304 Not Modified');
}else{
  //如果不相同则带上新的ETag,并输出页面数据
  header('ETag:'.$ETag);
  echo $s;
};
?>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇:php xdebug安装
下一篇:php递归

转载请注明:php etags 出自老鄢博客 | 欢迎分享