Solved

Don't cache html into hard drive

Posted on 2000-02-25
9
190 Views
Last Modified: 2010-03-05
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
Comment
Question by:tanc02
9 Comments
 
LVL 3

Expert Comment

by:guadalupe
ID: 2558327
I'm confissed which is what is really happening and which is what you want to have happen...?
0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2558431
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
 
LVL 1

Author Comment

by:tanc02
ID: 2558565
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 16

Expert Comment

by:maneshr
ID: 2558616
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
 
LVL 1

Author Comment

by:tanc02
ID: 2558896
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
 
LVL 16

Expert Comment

by:maneshr
ID: 2558966
remove the :8038 from the $DOMAIN var & then try.
0
 
LVL 1

Author Comment

by:tanc02
ID: 2559028
It is working now. But how
to do it in non-cookie version.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2559100
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
 
LVL 3

Expert Comment

by:jyu_88
ID: 2559122
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl match and sort unique result 2 136
How to get all the API from website? 11 89
Perl tar error 8 66
Export Variables in Perl 3 68
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question