Page 1 of 1

Undefined variable and character display in Opera

Posted: Fri Feb 06, 2009 10:11 am
by fido-x
I got the following error in Opera:--
Notice: Undefined variable: gzdata in system/library/response.php on line 50
The relevant line of code reads --

Code: Select all

$gzdata .= gzencode($data, (int)$level);
Changing this to --

Code: Select all

$gzdata = gzencode($data, (int)$level);
resolves this error.

However, the biggest issue is character display. See attached screenshot.

Re: Undefined variable and character display in Opera

Posted: Fri Feb 06, 2009 10:44 am
by bthirsk
Fido
In \catalog\view\template\module/layout.tpl

swap line 1 with line 3
I think that will cure the rendering problem.

Re: Undefined variable and character display in Opera

Posted: Fri Feb 06, 2009 7:23 pm
by gaudi
I encounter the same problem. I manage to resolve the $gzdata error using Fido instructions.

I also changed the layout.tpl template. The correct code I presumed should look like this:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $direction; ?>" lang="<?php echo $language; ?>" xml:lang="<?php echo $language; ?>">
<?php echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; ?>
<head>
But the strange characters are still there.

Re: Undefined variable and character display in Opera

Posted: Fri Feb 06, 2009 9:21 pm
by JNeuhoff
I can confirm this bug: I get the strange characters in Opera 9.63 and in Konqueror 4.1.3.

As a quick workaround, don't use the compression for the response output:

Code: Select all

	private function compress($data, $level = 4) {

//		if (strpos(@$_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
//			$encoding = 'gzip';
//		}

//		if (strpos(@$_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip')) {
//			$encoding = 'x-gzip';
//		}
		......
This is not a complete solution, but at least it gets Opera and Konqueror going again.

Re: Undefined variable and character display in Opera

Posted: Sat Feb 07, 2009 1:52 am
by Daniel
i'm posting a fix for this in the next release. I think the strange charater problem issomthing to do with the database installer.

Re: Undefined variable and character display in Opera

Posted: Sat Feb 07, 2009 2:03 am
by Daniel
Copy and paste this into your response class:

Code: Select all

<?php
final class Response {
	private $headers = array(); 
	private $output;

	public function addHeader($key, $value) {
		$this->headers[$key] = $value;
	}

	public function removeHeader($key) {
		if (isset($this->headers[$key])) {
			unset($this->headers[$key]);
		}
	}

	public function redirect($url) {
		header('Location: ' . $url);
		exit;
	}

	public function setOutput($output) {
		$this->output = $output;
	}

	private function compress($data, $level = 4) {
		if (strpos(@$_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
			$encoding = 'gzip';
		} 

		if (strpos(@$_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip')) {
			$encoding = 'x-gzip';
		}

		if (!isset($encoding)) {
			return $data;
		}

		if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) {
			return $data;
		}

		if (headers_sent()) {
			return $data;
		}

		if (connection_status()) {
			return $data;
		}

		$gzdata = gzencode($data, (int)$level);

		$this->addHeader('Content-Encoding', $encoding);

		return $gzdata;
	}

	public function output($level = 4) {
		if ($level) {
			$ouput = $this->compress($this->output, $level);
		} else {
			$ouput = $this->output;
		}		
		
		foreach ($this->headers as $key => $value) {
			header($key. ': ' . $value);
		}
				
		echo $ouput;
	}
}
?>

Re: Undefined variable and character display in Opera

Posted: Sat Feb 07, 2009 3:00 am
by JNeuhoff
Thanks, that works. It looks like the HTTP-header 'Content-Encoding' needs to be placed before the other headers.