Newbie CGI Question

J

jch

I'm trying to learn about using CGI scripts. I've written a very basic PERL
cgi called test.pl:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello - IT WORKS!!\n";

I can invoke this CGI and get the proper reults from a web page using:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="/cgi-bin/test.pl">Click</a>
</body>
</html>

I can also run the CGI directly using: www.mysite.com/cgi-bin/test.pl

What I really want to do is invoke the CGI from a web page without the user
having to click on anything. Ex: display the current date on a page. How
should I do this? I've tried a SSI but this doesn't work:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<!-- #include virtual="/cgi-bin/test.pl" -->
</body>
</html>

Sorry for the basic question. I've done a lot of Googling and haven't found
the answer. Thank you.
 
E

Ethan Schlenker

What I really want to do is invoke the CGI from a web page without the user
having to click on anything. Ex: display the current date on a page. How
should I do this? I've tried a SSI but this doesn't work:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<!-- #include virtual="/cgi-bin/test.pl" -->
</body>
</html>

If you want to execute a file, you can try using the SSI exec command
(instead of the include command). Try using:

<!--#exec cgi="/cgi-bin/test.pl" -->

instead of the SSI directive you have in your code above. Though exec
support can be a bit scattershot, so this may or may not work, but it's
worth a shot.

Ethan
 
K

Kim André Akerø

jch said:
I'm trying to learn about using CGI scripts. I've written a very basic PERL
cgi called test.pl:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello - IT WORKS!!\n";

I can invoke this CGI and get the proper reults from a web page using:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="/cgi-bin/test.pl">Click</a>
</body>
</html>

I can also run the CGI directly using: www.mysite.com/cgi-bin/test.pl

What I really want to do is invoke the CGI from a web page without the user
having to click on anything. Ex: display the current date on a page. How
should I do this? I've tried a SSI but this doesn't work:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<!-- #include virtual="/cgi-bin/test.pl" -->
</body>
</html>

Sorry for the basic question. I've done a lot of Googling and haven't found
the answer. Thank you.

There shouldn't be a space between the <!-- and the #. If you remove the
space, and it still doesn't work (the comment shows in the source code when
you open it in a browser), you may not have SSI available on your server.

<!--#include virtual="/cgi-bin/test.pl" -->
This should be enough if you're writing content (HTML or text). If you plan
on redirecting the request (using the header "Location:
http://new.url.here\n\n"), you should use <!--#exec
cgi="/cgi-bin/test.pl" --> instead.
 
M

Mitja

jch said:
I'm trying to learn about using CGI scripts. I've written a very basic PERL
cgi called test.pl:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello - IT WORKS!!\n";

I can invoke this CGI and get the proper reults from a web page using:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="/cgi-bin/test.pl">Click</a>
</body>
</html>

I can also run the CGI directly using: www.mysite.com/cgi-bin/test.pl

What I really want to do is invoke the CGI from a web page without the user
having to click on anything. Ex: display the current date on a page. How
should I do this? I've tried a SSI but this doesn't work:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<!-- #include virtual="/cgi-bin/test.pl" -->
</body>
</html>

Sorry for the basic question. I've done a lot of Googling and haven't found
the answer. Thank you.


Modify your test.pl so it doesn't only display date and time, but also all
of the encapsulating HTML (i.e., all of the code you wrote above). Simply
going to www.mysite.com/cgi-bin/test.pl should then do what you want.

Mitja
 
J

jch

Toby A Inkster said:
But why do you need to?

Because I want to learn how! And secondly, the rudimentary thing I want to
do next is to have a CGI called to display the current date in a HTML
document. For this I would want the program called automatically when the
page is loaded and not require a user to have to click a button.
 
T

Toby A Inkster

jch said:
the rudimentary thing I want to
do next is to have a CGI called to display the current date in a HTML
document. For this I would want the program called automatically when the
page is loaded and not require a user to have to click a button.

==================
#!/usr/bin/perl
$d = `date`;
print <<EOF;
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Here is a Full HTML Page</title>
<head>
<body>
<h1>Here is a Full HTML Page</h1>
<p>And here is the date: $d.</p>
<p>The user doesn't have to click anything.</p>
</body>
</html>
EOF
==================
 
J

jch

Kim André Akerø said:
There shouldn't be a space between the <!-- and the #. If you remove the
space, and it still doesn't work (the comment shows in the source code when
you open it in a browser), you may not have SSI available on your server.

I do have SSI enabled but.... my fault! I needed to use shtml. Storing
my test page with the .shtml extension caused the server to parse each line
and act on the "include" statement. Duh...
 
M

Marc Nadeau

jch a écrit:
Going to www.mysite.com/cgi-bin/test.pl works now. The issus is that I
can't seem to call the program from an HTML document.


Mitja advice is the best you can have.

perl is not like a client-side scripting language that is contained in html
but is best used to generate html code.

Some perl-based sites do not contain a single html file.
 
J

jch

Marc Nadeau said:
jch a écrit:



Mitja advice is the best you can have.

perl is not like a client-side scripting language that is contained in html
but is best used to generate html code.

Some perl-based sites do not contain a single html file.

Can you show me one of those sites as an example? Thx.
 
M

Marc Nadeau

jch a écrit:
Can you show me one of those sites as an example? Thx.

http://www.mon-oueb.com/fonderie

It is made of 2 perl scripts. A fonts repository interacting with a mysql
database.

The home page is the only hand edited html file but it was not necessary.

The css design is a work in progress but the site is fully functionnal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top