JDT

 

John Dixon
Technology
Limited

 
Google

Automatically Running a Script from within a Web Page


It is very simple to run a script (for example, a CGI script) by clicking a button in a form:

<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 <IN>;
    close IN;

There also needs to be an image called image.gif in the same directory (which is probably called cgi-bin) as the cgi script.

I often use this technique to 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 in order for the updates to take place.

Author: John Dixon
John Dixon Technology Ltd







Go back to Perl Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE open source accounting / bookkeeping software tool.

Earnings Tracker is aimed at UK contractors and freelancers, and enables you to perform many bookkeeping and accounting tasks, helping you to keep track of your company's earnings and outgoings.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

As it is written in open source software, you are free to modify the code yourself, enabling you to produce a customized version of Earnings Tracker that fits your own specification.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 


JDT

© 2007-2009 - John Dixon Technology Ltd

Privacy Statement

Terms & Conditions