Automatically Running a Script From Within a Web Page
(Note that in the code snippets in this article, square brackets are used instead of angle brackets.)
[form name="form1" method="post" action="/cgi-bin/updatePage.cgi"]
:
:
[/form]
Sometimes, however, you might need to run a script automatically from within an HTML page, without requiring the user to perform an action. You might want to do this if, for example, you have one or more variables that have been generated perhaps by another script, which you need to process without user interaction.
If you insert the following code into an HTML page, the script (in our case, updatePage.cgi) will be automatically executed when the web page is loaded into a browser.
[img src="/cgi-bin/updatePage.cgi" height="1" width="1"]
In order to ensure that a broken link is not generated by the cgi script itself, include the following code in the script.
print "Content-type: image/gif";
open IN, 'image.gif' or die "Cannot open: $!";
binmode IN;
print while ;
close IN;
There also needs to be an image called image.gif in the same directory (cgi-bin) as the cgi script.
I often use this technique automatically perform certain text processing activities in my content management systems. For example, I might have one or more ASCII files that need to be automatically updated at the end of an operation, but I don't want to force the user to click, for example, an update button.
Related Tags: web, html, running, perl, cgi, page, script, executing
About the Author: John Dixon is a web developer and technical author. These days, John spends most of his time developing dynamic database-driven websites using PHP and MySQL.
Go to http://www.computernostalgia.net to view one of John's sites. This site contains articles and photos relating to the history of the computer.
To find out more about John's work, go to http://www.dixondevelopment.co.uk.
Recent articles in this category:
- Take the Wheel - Drive Customers to your Website
So you own a small business and you have made the decision to build a simple website to gain interne - Hosting Geeklog Sites----Leading To a Booming Online Community
The weblogs are increasingly viewed as a cheaper alternative of expensive content management system. -
-
-
-
-
- Joomla Revolution! How This Free Software Is Changing The Web?
Joomla is changing the web, there is no one better sentence to describe what this young FREE SOFTWAR - Spicing Up Your Blog with 3D Animated YouTube Playlists
People have blogs for different purposes, some people maintain a blog purely for commercial reasons, - Free Image Hosting Service
Image hosting is a part of most web hosting services, providing hosting solutions for images instead
Most viewed articles in this category:
- Beyond the Brand
After completing a "Who, What, Where, Why and How" exercise, there are a few more steps to preparing - SharePoint 2007 New Feature Overview
Sharepoint 2007 is in Beta 2 now and is projected to be released at the beginning of the year but n - Build A Better Website
Building a website isn't usually rocket science, but you have to do your homework. Just like buying - How To Install SharePoint 2007 Beta 2
Following are the detailed instructions on how to install SharePoint 2007 Beta 2 on a clean version - How To Accomplish Your Goals With A Web Site
Choosing a small business idea to reach your goals is not easy. You'll need a strong spirit and dete - The Best Web Sites Aren't Free
The best web sites aren't free. While you may be tempted to buy an HTML book and try to put a few we - URL Forwarding and Redirection
Webmasters and common Internet users have a constant need for URL forwarding and redirection. The r - Web Site Development with Ruby on Rails and Other Programs
Web site development is a very big business these days. Almost every company in the world is trying - Self Assessment: How Effective is Your Web Site?
1. Fonts are an important attribute of a Web site. It is essential that fonts are large and c - For Automated Sites - PHP and MySQL are A Perfect Match
You’ve decided to automate your web site. Now what? Here are some ideas to help you choose how