Solved

Clear the cache in PHP

Posted on 2007-04-03
11
589 Views
Last Modified: 2008-02-01
Is there any way to clear cache in PHP? I have tried following codes. But they did not worked for me.

1)
    header("Cache-Control: post-check=0, pre-check=0",false);
     session_cache_limiter("must-revalidate");

2)
Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
Header("Pragma: no-cache");
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");

3)
<META http-equiv="expires" content="0">

and   4)
// calc an offset of 24 hours
  $offset = 3600 * 24;      
// calc the string in GMT not localtime and add the offset
  $expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
//output the HTTP header
  Header($expire);

Please help me. Thanking in advance.

0
Comment
Question by:Web_Sight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18842346
I use this set of headers which work for me:

        header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
        header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
        header( "Cache-Control: no-cache, must-revalidate" );
        header( "Pragma: no-cache" );
0
 

Author Comment

by:Web_Sight
ID: 18842430
I used this.  But it did not work for me.
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18842577
What are you trying to prevent from caching? Is there a proxy involved? The above headers should prevent caching for all major browsers...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Web_Sight
ID: 18874522
My code is embedding one image into another image.  I am not getting the result properly. But the image in the source folder is the latest one.  If I refresh the page, then it is displays the correct image.I am using proxy.

Further Explanation.
page1.php contains a main image and 3 other images which can drag over the main image.  I have dragged one image and place it over the main image.  The click on next button will lead to the control to the action page (page2.php) where actual emedding occurs. Then the result page (page3.php) displays.
page3.php displays the correct image on first time.  But when I go to page1.php and then embed a second image in the main image, then click 'Next' it displays only  the old image on page3.php.  If Iclick the refresh button, page3.php will display the correct image.
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18874546
Your situation might require a different approach. A well known 'trick' is to add a unique part to the URL by generating an extra parameter. This will fool the browser, proxy, etc. in that for them it will be a different URL.

It works like this, Add something like this to the URL's that are clicked on/ redirected to:
$url = 'http://your/url/your_page.php?rnd='.time();

0
 

Author Comment

by:Web_Sight
ID: 18887819
Still the problem exists. But this worked for a webpage where problem arise from macromedia flash. But it is not worked for my above issue.
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18887888
DO you save the new image after embedding and then load it again in page3.php? Can you post your display code from page3.php?
0
 

Author Comment

by:Web_Sight
ID: 18888519
Yes, new image is saving.
If I right click the property and take the URL of the image and paste it to a new browser window, I am getting the latest image.
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 18888608
Good. Well, you can use the same trick with images. Just pass a dummy parameter to the image URL and it should work:

echo '<img src="http://your/url/your_image.gif?rnd='.time().'">';
0
 

Author Comment

by:Web_Sight
ID: 18895771
THANK YOU. VERY MUCH. I have passed dummy parameters to the image URL and now it. is working nicely.
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18896033
You're welcome :)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question