I use gcache to cache whole website pages to HTML and next i only read it and show to the user. It looks like this:
$enableCache = true;
if ($enableCache)
{
include("gcache.php");
$cache = new gCache;
$cache->folder = "temp/";
$id = join("", $_GET);
$id = ereg_replace("[^A-Za-z0-9]", "", $id);
$cache->contentId=$id;
$cache->timeout = 5;
/* its mean gCache cached the whole page */
/* so, gcache, decide if he must response the compressed or */
/* uncompressed cache*/
$cache->isPage = true;
if ($cache->Valid()) {
echo $cache->content;
die;
}
$cache->capture();
}
And works fine. Now i’ve added a link “login” in the header of the site. When person clicks it it redirects person to subpage where he/she provides creditencials, session parameter is set (before is session_start called):
$_SESSION['theUser'] = $userId;
header( "refresh:1;url=http://mysite.com");
And person is redirected to the mysite.com. But the problem is he / she sees the site got from cache. So in upper right corner there is “log in” again, but i set that when $_SESSION[‘theUser’] is set it should show it and provide a link to log out. But it does not display because it returns to user the unlogged in version of website.
How to fix this?
I assume, that the reason of using cache in this way is to minimize server load and response times. But this can be achieved by more simple way not using third-parity plugins/classes/stuff:
Note: You must use
register_shutdown_function()instead of usingcacheOutputtoFile()as parameter of
ob_start()as socket is already closed when callback function is called, then the client not get the echo$webpageoutput.Usage: Put this file in your root server folder (or wherever you want) and require it one on top of every page you want to cache.