Hi alpal, first try to rename your html file with .shtml extension, probably this is the extension used with the following directive listed in your httpd.conf:
AddType text/html .shtml AddHandler server-parsed .shtml
In your .htaccess file you should add:
Options +Includes
if not already set in your system wide Apache configuration file. Then use the following SSI command:
<!--#include virtual="/cgi-bin/counter.pl" -->Note that the correct attribute is virtual and not cgi. There is an SSI howto on Apache site: Apache Tutorial: Introduction to Server Side Includes.
Finally, there is a race condition in your script, what happens if two instances of your script try to access the counter.txt file at the same time? You would probably screw your counter. You need to lock counter.txt before using it. There is a nice introduction to this subject in perlopentut (perldoc -m perlopentut), with the piece of code you need:
use Fcntl qw(:DEFAULT :flock); sysopen(FH, "numfile", O_RDWR | O_CREAT) or die "can't open numfile: $ +!"; # autoflush FH $ofh = select(FH); $| = 1; select ($ofh); flock(FH, LOCK_EX) or die "can't write-lock numfile: $!"; $num = <FH> || 0; seek(FH, 0, 0) or die "can't rewind numfile : $!"; print FH $num+1, "\n" or die "can't write numfile: $!"; truncate(FH, tell(FH)) or die "can't truncate numfile: $!"; close(FH) or die "can't close numfile: $!";
HTH, Valerio
In reply to Re: execute perl script in html
by valdez
in thread execute perl script in html
by alpal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |