Solved

Don't cache html into hard drive

Posted on 2000-02-25
9
170 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now