Page 1 of 1

PHP Cache

Posted: Thu Aug 22, 2002 5:43 pm
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>

Posted: Thu Aug 22, 2002 6:21 pm
by hob_goblin
I dont know, but I doubt it is wise to run an asp AND php page..

Posted: Thu Aug 22, 2002 6:45 pm
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>

Posted: Fri Aug 23, 2002 10:39 am
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

Posted: Fri Aug 23, 2002 10:49 am
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?

Posted: Fri Aug 23, 2002 11:05 am
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.