0

Getting error

PHP Notice: Undefined variable: do_not_compress

in my php code.

session_start();
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') &&  !$do_not_compress) {
    ob_start('ob_gzhandler');
} else {
    ob_start();
}

I tried to remove the && !$do_not_compress then throw another error

PHP Warning: ob_start(): output handler 'ob_gzhandler' cannot be used twice.
PHP Warning: ob_start(): failed to create buffer

Please help to fix this issue.

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • 4
    Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Rajdeep Paul Dec 03 '16 at 20:11

1 Answers1

0

Firstly, if $do_not_compress has not been set before it reaches this point then it's not going to be able to observe the value of it. If you're trying to use ! to see if it's not been set yet, then you should be using isset().

Secondly, I haven't used ob_start() but it appears to be that you can't call "ob_start('ob_gzhandler');" more than once in your code. So to fix the error there, don't. Here's something that may help you check before calling: How to determine wether ob_start(); has been called already

Community
  • 1
  • 1
Maytch
  • 71
  • 5