PHP Classda səhv hardadır
Salamlar. Belə bir gzip class hazırlamışam. Daha dogrusu hazır bir necə kod idi sadecə biraz el gəzdirib class formasına saldım. İlk oncə clasın quruluşuna baxmanızı xahiş edirəm. Düzgün olub olmadığı barədə. Və ya hər hansı artıq və ya əskik kodlar varmı classda?
2 cisi isə bu clası php shifəyə tətbiq edirəm səhifəyə opera brovvseri ilə daxil olanda heç bir problem olmur. ama IE,Firefox,Chrome ilə səhifə açılmlr. Error verir. Sizcə nədən ola bilər bu. Öncədən hər birinizə təşəkkür edirəm
[code]class Sixilma {
public static $addim = 5; //(-1, 9) arası qiymet alır. 5 ən optimalıdır
public static $compress;
public static $method;
function __construct() {
$this->compress();
$this->method();
$this->bashliq();
}
//Sistemin hansı tip sıxılmanı desteklediyini müəyyən eden funksiya
private function compress() {
if($_SERVER['HTTP_ACCEPT_ENCODING']) {
self::$compress = strtolower($_SERVER['HTTP_ACCEPT_ENCODING']);
} else {
self::$compress = strtolower($_SERVER['HTTP_TE']);
}
}
//Sistemin hansı metod sıxılmanı desteklediyini müəyyən eden funksiya
private function method() {
if(substr_count(self::$compress, 'deflate')) {
self::$method = 'deflate';
} else
if(substr_count(self::$compress, 'gzip')) {
self::$method = 'gzip';
} else
if(substr_count(self::$compress, 'x-gzip')) {
self::$method = 'x-gzip';
}
}
// Deflate
private function deflate($output) {
return gzdeflate($output, self::$addim);
}
//GZip
private function gzip($output) {
return gzencode($output, self::$addim);
}
//X-GZip
private function x_gzip($output) {
$size = strlen($output);
$crc = crc32($output);
$output = gzcompress($output, self::$addim);
$output = substr($output, 0, strlen($output) - 4);
return "\x1f\x8b\x08\x00\x00\x00\x00\x00".$output.pack('V', $crc).pack('V', $size);
}
//Sıxılma başlıq funksiyası
private function bashliq() {
if(self::$method == 'deflate') {
header('Content-Encoding: deflate');
ob_start($this->deflate);
ob_implicit_flush(0);
} else
if(self::$method == 'gzip') {
header('Content-Encoding: gzip');
ob_start($this->gzip);
ob_implicit_flush(0);
} else
if(self::$method == 'x-gzip') {
header('Content-Encoding: x-gzip');
ob_start($this->x_gzip);
ob_implicit_flush(0);
}
}
//Sıxılma sonluq funksiyası
public static function sonluq() {
$contents = ob_get_contents();
$in = strlen($contents);
switch(self::$method) {
default:
echo 'Sıxılma dəstəklənmir...';
break;
case 'deflate':
$out = strlen(gzdeflate($contents, self::$addim));
echo 'Sıxılma: '.round($in/1024,2).' / '.round($out/1024,2).' / '.round(100-(100/($in/$out)),1).'%';
break;
case 'gzip':
$out = strlen(gzencode($contents, self::$addim));
echo 'Sıxılma: '.round($in/1024,2).' / '.round($out/1024,2).' / '.round(100-(100/($in/$out)),1).'%';
break;
case 'x-gzip':
$out = strlen(gzcompress($contents, self::$addim));
echo 'Sıxılma: '.round($in/1024,2).' / '.round($out/1024,2).' / '.round(100-(100/($in/$out)),1).'%';
break;
}
}
}[/code]