Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7958249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:23:30+00:00 2026-06-04T04:23:30+00:00

I use gcache to cache whole website pages to HTML and next i only

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:23:31+00:00Added an answer on June 4, 2026 at 4:23 am

    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:

    <?php
        global $cachefile;
        //encode cache file name with sha1 
        $cachefilename = sha1($_SERVER['REQUEST_URI']);
        //remove trailing slash
        $cachefile = rtrim(sys_get_temp_dir (),'\\/').DIRECTORY_SEPARATOR.$cachefilename.'.cache';
         // How long to keep cache file?
        $cachetime = 60*5;    //5min
        // Is cache file still fresh? If so, serve it.   
        if (file_exists($cachefile) && filesize($cachefile)>100 && time() - $cachetime < filemtime($cachefile)  )  {
          readfile($cachefile);
          exit;
        }
    
        function cacheOutputtoFile()   {
         global $cachefile;
         $webpage = ob_get_contents();
         if ($fp = fopen($cachefile, 'w+'))
            {
                // Do an exclusive lock
                if (flock($fp, LOCK_EX))
                { 
                   // Truncate file 
                   ftruncate($fp, 0); 
                   fwrite($fp, $webpage);
                   fclose($fp);
                }
            }
        }
    
        ob_start();
        register_shutdown_function("cacheOutputtoFile");
    

    Note: You must use register_shutdown_function() instead of using cacheOutputtoFile()
    as parameter of ob_start() as socket is already closed when callback function is called, then the client not get the echo $webpage output.

    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.

    require_once("cacheable.php");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use this website a lot but first time posting. My program creates a number
Use Case When a user goes to my website, they will be confronted with
use Control::CLI; $cli = new Control::CLI('SSH'); $cli->connect(Host=>'10.10.10.10',Username=>'user',Password=>'pwd'); $cli->waitfor('>'); $cli->print('Show XXXXXXXXXXXXXXXXXXXX| grep Active'); @f=$cli->waitfor('>'); print
Use Html element SELECT in aspx page like: <SELECT id=MySelection name=MySelection runat=server DataValueField=ID DataTextField=Name></SELECT>
Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt
Use case: user clicks the link on a webpage - boom! load of files
Use case: User launches app The user enters google password The app lets the
Use Case: End-User searches for something and an ArrayCollection is returned with Result objects.
Use: The user searches for a partial postcode such as 'RG20' which should then
use DBI(); What is causing this insert to fail to err 1, the SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.