| By Bruce Van Horn | Article Rating: |
|
| March 11, 2002 12:00 AM EST | Reads: |
9,773 |
Sometimes I take for granted just how cool ColdFusion really is! The other day one of my programmers asked me how to do what I thought was a fairly easy task.
When I showed him the four lines of CF code he needed, he said, "ColdFusion rocks! It would have taken me 50 lines in PHP to do the same thing!" What could I say, other than "Yep"? Below are a few lines of code that I hope will make your life easier.
Q:How can we prevent a browser from caching the content of our Web pages? For example, our content is constantly changing; if a user browses a page, goes on to other pages, and then uses the back button to return to a previous page, we don't want the user seeing the same content he or she saw the first time - we want the user to see the updated content on that page. Can we do this?
A:Absolutely! Most browsers do cache page content to enhance the performance of site navigation. However, you can put some code into your pages that will instruct the browser not to cache their content. Unfortunately, different browsers require different no-cache parameters, so I use three tags to make sure it works in all browser versions. Place the following code at the top of each page you don't want cached:
<CFHEADER NAME="Expires"
VALUE="#Now()#">
<CFHEADER NAME="Pragma"
VALUE="no-cache">
<CFHEADER NAME="cache-control"
VALUE="no-cache, no-store,
must-revalidate">
Q:Our application needs to send out an e-mail message on behalf of our users; however, our mail server doesn't allow relaying from e-mail addresses outside our domain. We want the message to come from one of our e-mail accounts, but have a reply-to set to the address of the user who sent the message. I don't see any way for CFMAIL to set a "Reply-To" attribute. Can this be done?
A:This is a great question! Yes, it can be done now that CFMAIL can use the CFMAILPARAM tag. You may be aware that you can use the CF-MAILPARAM tag to send multiple file attachments, but you can also use it to send mail header information (like "Reply-To"). Here's all you have to do:
<cfmail to="paul@domain.com"Q:Is there a way to program ColdFusion to restart after so many database connection errors? And, more generally, is there a way of programmatically restarting ColdFusion?
from="noreply@abcgreet
ings.com"
subject="You have received a Birthday Greeting!">
<cfmailparam name="Reply-To"
value="yourfriend@somedomain.com">
Message body goes here...
</cfmail>
A:Yes and no. Yes in the CF Administrator - you can have CF restart after a certain number of failed requests (page or DB requests). You can get it to restart by checking the "Timeout requests after ___ seconds" box in the Settings section (be sure to set a timeout in seconds - do not leave it set to 0). Also check the "Restart at ___ unresponsive requests" box and plug in a number. Don't set either of these settings too low or CF will be restarting all the time.
There is no CF tag or function to restart the CF service, but you can write a .bat file to issue an NT command to stop or start the service:
net stop "World Wide Weband then call that .bat file using CFEXECUTE:
Publishing Service"
net stop "Cold Fusion
Executive"
net stop "Cold Fusion RDS"
net stop "Cold Fusion
Application Server"
net start "Cold Fusion
Application Server"
net start "Cold Fusion RDS"
net start "Cold Fusion Executive"
net start "World Wide Web
Publishing Service"
<!--- build a form that has a submit button on it and points to this action page --->
<cfif isDefined("Form.restart")>
<cfexecute
NAME="C:\websrvr\htdocs\restart
svcs.bat"/>
All webservices (IIS & CF)
will be restarted. Please
check back in 30 seconds.
</cfif>
Please send your questions about ColdFusion (CFML, CF Server, or CF Studio) to AskCFDJ@sys-con.com. Visit our archive site at www.netsitedynamics.com/AskCFDJ.
Published March 11, 2002 Reads 9,773
Copyright © 2002 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Bruce Van Horn
Bruce Van Horn is president of Netsite Dynamics, LLC, a certified ColdFusion developer/instructor, and a member of the CFDJ International Advisory Board.




























