PDA

View Full Version : Why does the script code display on web page


yogi_bear_79
01-24-2007, 02:42 AM
I am trying to use this simple script

#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
my $file = "c:/webs/www.hollywoodoil.com/data/counter.txt";
open( LOG, "$file" ) or die "Cannot open file $!";
my $cnt = <LOG>;
close(LOG);
++$cnt;
open( LOG, "> $file" ) or die "Cannot open file $!";
print LOG $cnt;
close(LOG);
#print "$cnt";
print "test";


HTML CODE:
<p><!--#include virtual="/includes/count.pl" --></p>

I have tried include file, and exec all have the same results. The code is printed on my web page. I use a perl form mail script on this site which works fine. The web server admin doesn't see a problem. When I call the script directly via the URL the counter.txt file increments.

I have even tried a simple Hello World script, all have the same results. I even used a counter script from another web server I use and it does the same thing.

david_kw
01-24-2007, 08:47 AM
Have you tried something like this?

<!--#exec cgi="/includes/count.pl"-->

Also you have to make sure your includes directory allows scripts I believe. And that your SSI allows exec.

I think I have just written everything I know about SSI. =P

david_kw

KevinADC
01-24-2007, 06:49 PM
you have to print an http header even in a perl script accessed via an SSI tag:

so before these lines:

#print "$cnt";
print "test";

add:


print "Content-type: text/html\n\n";

but thats not the reason the code displays instead of the output of the code (the counter value). All I can figure is it's a server setup issue because the script does run from the URL.

yogi_bear_79
01-25-2007, 12:24 AM
It turned out to be a combination of items. To see the results I need this as suggested: print "Content-type: text/html\n\n";

And I went back to <!--#exec cgi="/includes/count.pl"--> which fixed the main problem. I had used that statement before but apparently in all of my testing (i had three test scripts) I just never used the right combo. Thanks