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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.