My page is not cached !!! why

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

My page is not cached !!! why

Post by bow »

As the subject suggests , my page is not cached in the browser , what can be the problem?
my page structure is this:

Code: Select all

 
<?php
session_start();
include("includes/photo.inc.php");
include("includes/title.inc.php");
$in="index";
if (! @include('includes/connection.inc.php')) {
    echo 'Sorry, database unavailable';
    exit;
}
define('SHOWMAX',5);
$conn = dbConnect('query');
$getTotal = 'SELECT COUNT(*) FROM news';
$total = $conn->query($getTotal);
$row = $total->fetch_row();
$totalPix = $row[0];
$curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0;
$conn = dbConnect('query');
$startRow = $curPage * SHOWMAX;
$sql = "SELECT * FROM news ORDER By created DESC LIMIT $startRow,".SHOWMAX;
$result = $conn->query($sql) or die(mysqli_error());
$row = $result->fetch_assoc();
include("includes/log.inc.php"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ryde Secondary College <?php echo "&#8212;{$titl}"; ?></title>
<link href="contents/thrColHybHdr.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.thrColHybHdr #sidebar1, .thrColHybHdr #sidebar2 { padding-top: 30px; }
.thrColHybHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
</head>
 
<body class="thrColHybHdr">
 
<div id="container">
  <div id="header">
    <div align="right" id="logo">
    <a class="title"><?php echo "$titl"; ?></a>
      <img id="bos" src="contents/images/board_of_studies_nsw_05.gif" alt="Board of Studies" width="157" height="36" /><img src="contents/images/logo_det.gif" alt="Department of Education" name="det" width="100" height="41" id="det" /><a href="http://www.tafensw.edu.au/"><img src="contents/images/LOGOTAFE.gif" alt="TAFE" name="tafe" width="55" height="41" border="0" id="tafe" /></a></div>
  <!-- end #header --></div>
  <div id="container2">
    <table class="container2" >
      <tr>
        <td align="center" valign="top" id="sidebar2">
          <div id="calender"> <?php include("includes/calender.inc"); ?></div>
          <div id="LeftMenu"><?php include("includes/imenus1.inc"); ?></div>
        </td>
        <td style="width:10px" background="contents/images/Sh_left.gif">&nbsp;</td>
        <td id="mainContent">
            <div id="menu" >
            <?php include("includes/imenus0.inc"); ?>
            </div>
            <div id="text">
            <?php do { ?>
                    <h3><?php echo $row['title'] ?></h3><br>
                    <div align="right"><?php echo $row['created'] ?></div><br>
                    <?php echo nl2br($row['body']) ?>
                    <?php
                        $row = $result->fetch_assoc();
                        } while ($row);
                    ?><br />
                    <div id="page">
                    <?php
                    if ($curPage > 0) {
                      echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'">< Prev</a>';
                      }
                    else {
                      echo '&nbsp;';
                      }
                      ?>&#8226;&deg;&#8226;
                      <?php
                    if ($startRow+SHOWMAX < $totalPix) {
                      echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'">Next ></a>';
                      }
                    else {
                      echo '&nbsp;';
                      }
                    ?>
                    </div>
          </div>        </td>
        <td style="width:10px" background="contents/images/Sh_right.gif">&nbsp;</td>
        <td align="center" valign="top" id="sidebar1">
        <div id="image-box">
            <div id="image">
            <img src="pictures/<?php echo $img ?>" width="150">   </div>
        </div>
        <div id="login-box">
        <?php if( isset($_SESSION['authenticated'])) { ?>
        Welcome <?php echo $_SESSION['user'] ; ?> </br>
        You are logged in </br>
        <a href="user/index.php">My control pannel </a>
        <?php } else { ?>
        <form id="form1" name="form1" method="POST" action="">
                  <p>
                    <label>
                    <input name="username" type="text" id="name" value="User name" size="10" />
                    </label>
                </p>
<p>
                    <label>
                    <input name="pwd" type="password" id="pass" value="Pass" size="12" />
                    </label>
          </p>
                  <p align="right">
                    <input name="login" type="submit" id="login" value="Log in" />
          </p>
      </form>
      <?php } ?>
    <h6><?php echo "$error"; ?></h6>
    </div>
        </td>
      </tr>
    </table>
    <br class="clearfloat" />
  </div>
  <div id="footer">
    <?php include("includes/footer.inc"); ?>
  <!-- end #footer --></div>
<!-- end #container --></div>
 
</body>
</html>
 
 
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: My page is not cached !!! why

Post by Christopher »

How do you know it is not cached?

Are there any header() calls in:

Code: Select all

include("includes/photo.inc.php");
include("includes/title.inc.php");
 
(#10850)
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

I checked with opera and firefox and it is not cached there(except the images)

and there is not any header in my includes
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: My page is not cached !!! why

Post by Chris Corbyn »

Could apache perhaps be sending no-cache headers for .php content?

Do you use FireBug at all? You'd be able to see what headers are being sent by the server then.
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

How should I know if apache is sending no capcher for .php ?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: My page is not cached !!! why

Post by Chris Corbyn »

See my last post regarding firebug (its a firefox extension).
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

in the header I found this:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
but I haven't done any thing to do this!
actually I added this to see if it makes it better :

Code: Select all

header("Content-type: text/html; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 * 24 * 3;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
but still it doesnt work
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

anyone has any idea?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: My page is not cached !!! why

Post by Chris Corbyn »

Those headers actually tell the browser *not* to cache the page. "must-revalidate", "no-cache", "no-store".... fairly obvious really ;)
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

I know this.... :banghead:
my problem is HOW TO GET RID OF THIS ??!!!!!

I tried any possible way I could think , didn't work
and thats why I'm here, I know it tells the browser not to cache this page , but I want to know why and how to fix it
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: My page is not cached !!! why

Post by Chris Corbyn »

Maybe I'm missing something? Removing those calls to header() would do just that :?:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: My page is not cached !!! why

Post by Chris Corbyn »

Ah, so you saw those headers, and then added those calls to header()?

The Cache-Control header still tells the broswer not to cache.

Have you got a .htaccess file in this directory, or above it for that matter?
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

yes I added thos calls to solve the problem , but it didn't change
and I dont have any .htaccess :(
bow
Forum Newbie
Posts: 10
Joined: Mon Feb 18, 2008 12:00 am

Re: My page is not cached !!! why

Post by bow »

Actually I can say my question is how to force the browser to cache a page :?:
Post Reply