<?
Ob_start ();
Ob_implicit_flush (0); <a id = "more-27"> </a>
Function CheckCanGzip (){
Global $ HTTP_ACCEPT_ENCODING;
If (headers_sent () | connection_timeout () | connection_aborted ()){
Return 0;
}
If (strpos ($ HTTP_ACCEPT_ENCODING, 'x-gzip ')! = False) return "x-gzip ";
If (strpos ($ HTTP_ACCEPT_ENCODING, 'gzip ')! = False) return "gzip ";
Return 0;
}
/* $ Level = compression level 0-9, 0 = none, 9 = max */
Function GzDocOut ($ level = 1, $ debug = 0 ){
$ ENCODING = CheckCanGzip ();
If ($ ENCODING ){
Print "\ n <! -- Use compress $ ENCODING --> \ n ";
$ Contents = ob_get_contents ();
Ob_end_clean ();
If ($ debug ){
$ S = "<p> Not compress length:". strlen ($ Contents );
$ S. ="
Compressed length: ". strlen (gzcompress ($ Contents, $ level ));
$ Contents. = $ s;
}
Header ("Content-Encoding: $ ENCODING ");
Print "\ x1f \ x8b \ x08 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ";
$ Size = strlen ($ Contents );
$ Crc = crc32 ($ Contents );
$ Contents = gzcompress ($ Contents, $ level );
$ Contents = substr ($ Contents, 0, strlen ($ Contents)-4 );
Print $ Contents;
Print pack ('V', $ Crc );
Print pack ('V', $ Size );
Exit;
} Else {
Ob_end_flush ();
Exit;
}
}
?>