Completed
Push — master ( 81081e...df7b08 )
by Harald
06:26 queued 03:10
created

catalog/includes/functions/gzip_compression.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
  * osCommerce Online Merchant
4
  *
5
  * @copyright (c) 2016 osCommerce; https://www.oscommerce.com
6
  * @license MIT; https://www.oscommerce.com/license/mit.txt
7
  */
8
9
  function tep_check_gzip() {
10
    if (headers_sent() || connection_aborted()) {
11
      return false;
12
    }
13
14
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) return 'x-gzip';
15
16
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) return 'gzip';
17
18
    return false;
19
  }
20
21
/* $level = compression level 0-9, 0=none, 9=max */
22
  function tep_gzip_output($level = 5) {
23
    if ($encoding = tep_check_gzip()) {
24
      $contents = ob_get_contents();
25
      ob_end_clean();
26
27
      header('Content-Encoding: ' . $encoding);
28
29
      $size = strlen($contents);
30
      $crc = crc32($contents);
31
32
      $contents = gzcompress($contents, $level);
33
      $contents = substr($contents, 0, strlen($contents) - 4);
34
35
      echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
36
      echo $contents;
37
      echo pack('V', $crc);
38
      echo pack('V', $size);
39
    } else {
40
      ob_end_flush();
41
    }
42
  }
43
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
44