简体   繁体   中英

How to check if a page is cached with php

...and whether it was cached 30 days ago,,

I am using this code:

 $page=get_headers('http://www.w3schools.com/php/func_date_strtotime.asp');

The output is this:

 0=>HTTP/1.1 200 OK 

1=>Connection: close

2=>Date: Thu, 03 May 2012 10:51:00 GMT

3=>Server: Microsoft-IIS/6.0

4=>MicrosoftOfficeWebServer: 5.0_Pub

5=>X-Powered-By: ASP.NET

6=>Pragma: no-cache

7=>Content-Length: 23643

8=>Content-Type: text/html

9=>Expires: Thu, 03 May 2012 10:50:00 GMT

10=>Set-Cookie: ASPSESSIONIDSAARQQST=AAMAAHBBBHBELMHDCHNNLMFP; path=/

11=>Cache-control: no-cache

I read that pragma cache , doesnt necessary mean that the page is uncacheable.

I want to know 2 things: 1) if the page is cached 2) if it was cached 30 days ago.

Can I do this

 $date1=gmdate("D, d M Y H:i:s", strtotime("30 days ago")) . " GMT";
  $date2=$page['Expires'];
  if($date1>$date2)
  {
    echo 'The page was cached for longer than 30 days';
   }

Since PHP is a server side language you cannot check browser cache(which is a client side) using PHP. So you need some client side scripting like Javascript and not server side programming like PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM