View Full Version : How to call a CGI script within HTML
hogtied
12-21-2002, 08:12 AM
Hello members, kinda new to this perl thing and wondering if I can call a CGI script within HTML, but without using the Form submit and without leaving the page....
What I want to happed is that when a user comes to my home page then I want to count that user towards my counter, whether they send a form or not. I have the code, and it works, but only when I send submit a form.
Thanks,
Hotied :confused:
Philip M
12-21-2002, 08:25 AM
I am assuming that you have access to cgi on your server.
You will need a simple counter script and then
in your html page you can call it with
<!--#exec cgi="cgi-bin/counter.cgi"-->
Here is the counter script I use:-
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$tempcount = 0;
while($tempcount < 8)
{
$tempcount++;
if(-e "lock/myfile.lok")
{
sleep 2;
}
else
{
open (LOCK,">>lock/myfile.lok");
close LOCK;
open (COUNTER,"<counter.fil");
$count = <COUNTER>;
close COUNTER;
$count++;
open (COUNTER,">counter.fil");
print COUNTER ($count);
close COUNTER;
unlink "lock/myfile.lok";
last;
}
}
You will need to upload it. CHMOD 755, upload an empty
file called counter.fil, CHMOD that 777 and away you go.
If you want it to display on the page, then the HTML is something like:-
<p align="center"><font color="#FF0000" size="2" face="Arial">You are visitor number <!--#exec cgi="cgi-bin/counter.cgi"--> to this web site</font></p>
Hope this helps.
hogtied
12-21-2002, 08:39 AM
aahhhh that's what they me by server-side-include.. kewl.. I'll give a shot.. and to answer your question, yes I have access to my CGI bin..
Thanks,
Hogtied
santosh_mce
07-08-2010, 01:10 PM
Hi, I am trying execute cgi script from html page.
tried the above, but still I am not able to execute it.
HTML File:
msantosh-test:/srv/www/htdocs # cat test2.htm
<head>
<body>
Hello world
Calling script
<!--#exec cgi="cgi-bin/test1.cgi"-->
</body>
</head>
msantosh-test:/srv/www/htdocs #
CGI Script:
msantosh-test:/srv/www/cgi-bin # cat test1.cgi
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print ;
print "Santosh\n";
msantosh-test:/srv/www/cgi-bin #
msantosh-test:/srv/www/cgi-bin # ll test1.cgi
-rwxrwxrwx 1 root root 81 2010-07-03 02:41 test1.cgi
msantosh-test:/srv/www/cgi-bin #
Can you please me on this!!
Fou-Lu
07-08-2010, 05:07 PM
Hi, I am trying execute cgi script from html page.
tried the above, but still I am not able to execute it.
HTML File:
msantosh-test:/srv/www/htdocs # cat test2.htm
<head>
<body>
Hello world
Calling script
<!--#exec cgi="cgi-bin/test1.cgi"-->
</body>
</head>
msantosh-test:/srv/www/htdocs #
CGI Script:
msantosh-test:/srv/www/cgi-bin # cat test1.cgi
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print ;
print "Santosh\n";
msantosh-test:/srv/www/cgi-bin #
msantosh-test:/srv/www/cgi-bin # ll test1.cgi
-rwxrwxrwx 1 root root 81 2010-07-03 02:41 test1.cgi
msantosh-test:/srv/www/cgi-bin #
Can you please me on this!!
.htm isn't a default extension to process ssi. Rename it to shtml and see if that works.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.