Using HTTP Headers


An HTTP header passes information about requests by the browser and responses from the server. The information needed for the exchange to take place is included in the header without being displayed.

The <cfheader> tag sets attribute/value pairs in the response header. The attributes of the tag are shown in Table 5.2.

Table 5.2. <cfheader> Tag Attributes

ATTRIBUTE

DESCRIPTION

name

The name of the attributes to set

value

The value associated with the corresponding NAME


A common use of the <cfheader> tag is to prevent a Web page from being cached by the browser. This caching can cause a problem if the Web page is used to display data that is being updated in some way. If database data is inserted, updated, or deleted, and the page to display that data is cached by the browser, the database records might not be shown accurately on the page. The Web browser has an EXPIRES attribute, which you can set to some time in the past so that the page will always be expired. The code to do so is as follows:

 <cfheader name="Expires" VALUE="#Now()#"> 

The entry created in the header would look something like this:

 Normal Expires: {ts '2006-01-01 19:34:42'} 

TIP

If you run into a situation in which you need to prevent a page from being cached (for example, if proxy servers are being used), you must take into account different browsers and browser versions. The example shown here may not cover all possibilities. You might also want to test the following to be sure you get the best results for the range of browsers you are considering:

 <meta http-equiv="Pragma" content="No-Cache"> <meta http-equiv="Expires" content="0"> <cfheader name="Pragma" value="no-cache"> <cfheader name="cache-control"  value="no-cache, no-store, must-revalidate"> 




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net