PHP Cache

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
merlinti
Forum Newbie
Posts: 13
Joined: Mon Aug 19, 2002 1:24 pm
Contact:

PHP Cache

Post by merlinti »

Hi All,

I am just learning PHP. Please exscuse my newbieness.
I have a php page that keeps the form values after submitting it to the next page. I don't mind the php variables, it's the form variables like credit card # that I don't want cached.

This is somewhat how the page looks:
The no-cache is not working! :?


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Response.Expires = 60
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>
<html>
<head>
<title>Frank's Travel Services - Hotels</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#include file="meta.htm" -->
<link href="assets/css/mysite.css" rel="stylesheet" type="text/css">
</head>

<body>

<?php


// Set the variables for the database access:
$Host = "localhost";
$User = "username";
$Password = "password";
$DBName = "database";
$TableName = "$HotelSelect";

print ("<p><b><font #003399>Hotel:</font></b> $TableName</p>");
$TableName = ereg_replace("[\r\n\t\v\ ]", "", trim($TableName));

$Rooms = "$Rooms";
$CheckIn = "$CheckIn";
$CheckOut = "$CheckOut";
$price = 0;

print ("<p><b><font #003399>Check In Date:</font></b> $CheckIn</p>");
print ("<p><b><font #003399>Check Out Date:</font></b> $CheckOut</p>");

$Link = mysql_connect ($Host, $User, $Password);

$Query02 = "SELECT Price FROM $TableName WHERE (Dates BETWEEN '$CheckIn' AND '$CheckOut')";

mysql_select_db($DBName) or die(mysql_error());
$Result02 = mysql_query ($Query02) or die(mysql_error().'<br />'.$Query02);

while ($Row = mysql_fetch_array ($Result02)) {
$price = $price + $Row[Price];
}

print ("</TABLE>\n");

$TotalPrice = $Rooms * $price;

print ("<p><strong><font color='#003399' size='3'>TOTAL COST:</font></strong> <b>$$TotalPrice.00<b></p>");

mysql_close ($Link);

$CheckInDate = ("$CheckIn");
$CheckOutDate = ("$CheckOut");

?>


<form action="hotels02.php" method="post" name="HotelForm" id="HotelForm">


<input name="CardNumber" type="text" id="CardNumber">
<input name="CheckOut" type="hidden" id="CheckOut" value="<? echo $CheckOut ?>">
<input name="CheckIn" type="hidden" id="CheckIn" value="<? echo $CheckIn ?>">
<input name="Rooms" type="hidden" id="Rooms" value="<? echo $Rooms ?>">
<input name="TotalPrice" type="hidden" id="TotalPrice" value="<? echo $TotalPrice ?>">
<input name="HotelSelect" type="hidden" id="HotelSelect" value="<? echo $HotelSelect ?>">
<input name="Submit2" type="submit" value="Submit">
</form>

</body>
</html>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

I dont know, but I doubt it is wise to run an asp AND php page..
merlinti
Forum Newbie
Posts: 13
Joined: Mon Aug 19, 2002 1:24 pm
Contact:

Post by merlinti »

Hi,

I tried this too. But I'm getting these messages:

Warning: Cannot add header information - headers already sent by (output started at c:\inetpub\wwwroot\frankstravel\hotels01.php:1) in c:\inetpub\wwwroot\frankstravel\hotels01.php on line 1



<? Header('Cache-Control: no-cache');
Header('Pragma: no-cache');
?>
<html>
<head>
merlinti
Forum Newbie
Posts: 13
Joined: Mon Aug 19, 2002 1:24 pm
Contact:

Post by merlinti »

Hello,

I put this as the first lines of code on the page.
It gives the message: "Warning: Page has Expired" and forces the user to refresh the page by clicking Refresh.
Is there a way to automatically refresh it?
Also, the form inputs are erased but the PHP variables are still there
Why were these not reset?



<?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); // always modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache");
?>


thanks for any help
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

What exactly are you trying to accomplish? From all your code, I can gather 2 things. 1) You are running around without any clue as to where you are going, or 2) You actually want to accomplish something, you just haven't gotten around to actually telling us what it really is.

Would I be correct in assuming you want to prevent the following from happening:

1. User go to form, enters information, and submits form.
2. On the next page, user hits refresh, and the page asks him to reload.

I am assuming, you want to preven the second thing from happening?
merlinti
Forum Newbie
Posts: 13
Joined: Mon Aug 19, 2002 1:24 pm
Contact:

Post by merlinti »

Hi Jason,

Yes, if a user hits the back button I would like the form to be reset and all PHP variables to be reset. For security purposes, like credit card info.etc.

I understand how to use html and asp pages, but now i'm trying to learn how PHP works into it all this as well. I just started learning PHP, sorry about all the crazy questions.


I appreciate the help.
Post Reply