Our previous webmaster created this site, and its caching works fine for most browsers, but I found that some versions of Opera do not work, and some online SEO tools like Send Express Analyzer . I suspect this is a problem with the headers. I read about ob_start ("ob_gzhandler"), but I'm not sure how I can implement it in this scenario.
The entire site is managed by a router file, unique controller files for each page type, and .htaccess. The code below is in the router file to search for the cached version of the page and load the contents, otherwise load the page.
Caching compresses the contents of the page using gzencode and stores it in the database in the cache table with the uri hash code. If the cached file exists, the contents are retrieved from the database.
Opera displays a blank page, but the Express Express method does not recognize the page. I am pretty sure that the .htaccess file has nothing to do with this problem. Below is the code where I think the problem is.
<?php $loadTime = microtime(true); session_start(); if (!isset($_SESSION['var'])) $_SESSION['var'] = rand(0, 2); if (!isset($_SESSION['var2'])) $_SESSION['var2'] = rand(0, 4); require(dirname(__FILE__).'/config/common.php'); $uri = $_SERVER['REQUEST_URI']; $request = explode('/', substr($uri, 1)); $request = preg_replace('/\..*/', '', $request); $uriHash = sha1($uri); if($uri == '/')
Bad Index Code
} try { // LOOKS FOR CACHE IN DB BASED ON URI $cache = $GLOBALS['db']->getRow("SELECT * FROM cache_tbl WHERE uri_hash = '$uriHash'"); }catch ( Exception $e ) { $cache = array(); } if ( !empty($cache) && ($cache['mod_date'] * 60 * 60 * 24) > $loadTime ) { // IF NO CACHE IN DB, SETS HEADERS FOR COMPRESS OR NO COMPRESS $HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"]; if( headers_sent() ) $encoding = false; else if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ) $encoding = 'x-gzip'; else if( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ) $encoding = 'gzip'; else $encoding = false; $compressed = $cache['contents']; if ( $encoding ) { header("Content-Encoding: ".$encoding); echo $compressed; } } else { if ($request[0] == 'venues') { header("HTTP/1.1 301 Moved Permanently"); header('Location: '.HOST.$request[1].'.html'); }
More code
if ( // Irrelevant Conditions ) { $contents = ob_get_clean(); echo $contents; $compressed = gzencode($contents, 7); try { Admin::add('cache_tbl', array('uri_hash' => $uriHash, 'contents' => $compressed, 'mod_date' => $loadTime)); } catch(Exception $e) { ; } ob_end_flush(); } }
There is a lot going on in this file, and I tried to cut as many things as possible in order to eliminate the confusion. Any help is certainly greatly appreciated! Thanks in advance!