• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Don't cache html into hard drive

Here is what I have :

   print "Content-type: text/html\n\n";
   print "<meta http-equiv=\"Pragma\" CONTENT=\"no-cache\">";
   print "<meta HTTP-EQUIV=\"Expires\" CONTENT=\"0\">";
   .........
   .........

let say, I put this code into 2.html , so here is what the user did  :

  1.html -> 2.html -> 3.html

now user is at 3.html. So, when he bit Back Button, user will see :

Data Missing
This document resulted from a POST operation and has expired from the cache. If you wish you can repost the form data to
recreate the document by pressing the reload button.

so user isn't able to see the display of 2.html, but why if user hit Back button, the user can see the display again ? How to program it, so when user hit back button, user will see only 1.html ?
0
tanc02
Asked:
tanc02
1 Solution
 
guadalupeCommented:
I'm confissed which is what is really happening and which is what you want to have happen...?
0
 
maneshrCommented:
this script addresses the basic functionality that you are looking for (i.e. prevent user from seeing the 2nd page), but it does not hit the target 100%

any way here goes.

NOTE: if you go back from the 3rd page you will still get"


Data Missing
                   This document resulted from a POST operation and has expired from the cache. If you wish you
                   can repost the form data to
                   recreate the document by pressing the reload button. "

But at that point reload the page and see what happens.



=============1.html
<HTML>
<HEAD>
<TITLE>First Page</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<CENTER>
<FORM Method="POST" Action="/cgi-bin/2.pl">
<FONT COLOR="#006633"><B>Enter name:</B></FONT>
<INPUT NAME="name" TYPE="TEXT"><P>
<INPUT TYPE="SUBMIT" VALUE="Proceed>>">
</CENTER>
</FORM>
</BODY>
</HTML>


====================2.pl
#!/usr/local/bin/perl

use CGI;

$query=new CGI;
$DOMAIN=".ny.smb.com";

##  Cookie is not set
##  That means, the page has been called by a form, in the proper way.
if ($ENV{'HTTP_COOKIE'}!~ /back=yes/){
  $name= $query->param('name');
  ##  Un-Set a Domain cookie to prevent user from jumping
  ##  the sequence.
  print "Set-Cookie: back=yes; domain=$DOMAIN; path=/; \n";

  print "Content-type: text/html\n\n";
  print qq{
  <HEAD>
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="expires" content="0">
  </HEAD>
  <B>You are on the 2nd page<BR>This page has been generated by
  a CGI script</B>.

  <P>You entered <I>$name</I> on the previous page.

  <P>Click <a href="/manesh/3.html">here</a> to go to the 3rd page.

  };
}else{  ##  Cookie is set. Therefore this access method is valid
 print "Content-type: text/html\n\n";
 print "<meta http-equiv=\"Refresh\" content=\"0; URL=/manesh/1.html\">\n"; ##
 Re-direct user to the first page
}


==========================3.html
<HTML>
<HEAD>
<TITLE>Third Page</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FONT COLOR="#006633"><B>
This is the 3rd page. Use the "Back" Button on your browser
& try going back to the 2nd page.
</B></FONT>
</BODY>
</HTML>
0
 
tanc02Author Commented:
manehsr :

 It isn't working. Please go to :

http://imps.stcloudstate.edu:8038/1.html

I was a 3.html, then I hit BACK button and RELOAD, I still can see the 2.pl output.

Is that possible, when I was at 3.html, and hit back will bring me back to 1.html ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
maneshrCommented:
oh. you need to change the

$DOMAIN=".ny.smb.com";  variable to your domain name.

so if your URL is

www.tanc02.com, you have to make the change to $DOMAIN as follows

$DOMAIN=".tanc02.com";
0
 
tanc02Author Commented:
still doesn't work. Here is what I have for 2.pl :

#!/usr/bin/perl

use CGI;

$query=new CGI;
$DOMAIN=".stcloudstate.edu:8038";

# Cookie is not set, the page has been called by a form, in the proper way.
if ($ENV{'HTTP_COOKIE'}!~ /back=yes/){
  $name= $query->param('name');
  # Un-Set a Domain cookie to prevent user from jumping the sequence.
  print "Set-Cookie: back=yes; domain=$DOMAIN; path=/; \n";

  print "Content-type: text/html\n\n";
  print qq{<HEAD>
           <meta http-equiv="Pragma" content="no-cache">
           <meta http-equiv="expires" content="0">
           </HEAD>
           <B>You are on the 2nd page<BR>This page has been generated by
              a CGI script</B>.

           <P>You entered <I>$name</I> on the previous page.

           <P>Click <a href="http://imps.stcloudstate.edu:8038/3.html">here</a> to go to the 3rd page. };
}else{
  # Cookie is set. Therefore this access method is valid
     print "Content-type: text/html\n\n";
     print "<meta http-equiv=\"Refresh\" content=\"0; URL=http://imps.stcloudstate.edu:8038/1.html\">\n";
  # Re-direct user to the first page
}


What is user disabled cookie ?
0
 
maneshrCommented:
remove the :8038 from the $DOMAIN var & then try.
0
 
tanc02Author Commented:
It is working now. But how
to do it in non-cookie version.
0
 
maneshrCommented:
here's the reason i would not trust the non-cookie version.

Note the section on Pragma.

http://www.webdeveloper.com/html/html_metatags_part2.html
0
 
jyu_88Commented:
The following quotes from a great web-caching tutorial at http://www.csc.fi/WWW/cache/docs/web_cache.html    will explain why. Do go the tutorial to suit your needs.


"HTML authors can put tags in a document's <HEAD> section that describe its attributes. These Meta tags are
       often used in the belief that they can mark a document as uncacheable, or expire it at a certain time.
       Meta tags are easy to use, but aren't very effective. That's because they're usually only honored by browser caches
       (which actually read the HTML), not proxy caches (which almost never read the HTML in the document). While
       it may be tempting to slap a Pragma: no-cache meta tag on a home page, it won't necessarily cause it to be kept fresh, if it goes through a shared cache."
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now