PDA

View Full Version : putting CGI into html - help?


disto
08-15-2006, 10:18 PM
hi i want to put a cgi counter into a html file can anyone explain how i can do it because previously i have used the < i frame > to do this!

if someone could simply tell me how i could write the whole of a cgi file into a html file then i can work the rest from there

KevinADC
08-16-2006, 12:38 AM
you can't put a perl script in an html file, at least not easily. The html document has to make a call to a script, you can use an image tag to call a cgi script:

<img src="../counter.cgi" width='1' height='1' alt="just a counter">

disto
08-16-2006, 01:08 AM
ok so if my cgi file just said

hello world!

should that dislplay if i use the img tag?

disto
08-16-2006, 01:39 AM
ok ive tried it on an xitami server

i used a url.html
<html>
<head></head>
<body>
<img src='test2.cgi' width='100' height='100'>
</body>
</html>

and test2.cgi
#!C:/Perl/bin/perl
print "Content-type: text/html\n\n";
print "16464";
exit;


both files were situated in the cgi-bin

all i got was the small box with a red cross (image cannot be found logo)

where am i going wrong?

mlseim
08-16-2006, 02:37 AM
Most of the counter scripts online require this:

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

using #exec

But perhaps you can't use #exec with your server or webhost?


Here's a script that combines the graphic digits using ImageMagick,
if your server supports that ... (Note: I've never tried this script)

http://home.datacomm.ch/atair/yac/


.

KevinADC
08-16-2006, 06:05 AM
I assumed you already had a graphical counter you were using. If you want a plain text counter use the "include virtual" SSI tags to call your cgi script.

<!--#include virtual="../cgi-bin/counter.pl?page=index.html" -->

where "page=index.html" tells your script which counter to use, you are of course free to decide that mechanism for yourself. You also have to rename your html files to .shtml usually for SSI parsed pages.

You can always stick with the iframe tag too to display a plain text counter:

<HTML>
<HEAD>
<TITLE>Homepage</TITLE>
</head>
<body>
This page has been visted <iframe style="border: none; overflow: hidden; width: 60px; height: 25px; padding: 0; margin: 0;" src="../cgi-bin/counter2.pl"></iframe> times
</body></html>

both files were situated in the cgi-bin

Normally you can't access static documents like html pages that are in the cgi-bin all though your server maybe setup to allow that.

FishMonger
08-16-2006, 08:01 AM
If you're going to use a perl script to show a text based counter, this module would be one of the better approaches.

http://search.cpan.org/~gaas/File-CounterFile-1.04/CounterFile.pm

disto
08-16-2006, 10:09 AM
ahhh it didnt work! dont you just hate it when you cant get something that seems so simple to work!

i prefer to create my own scripts basically because then i find it easier to write a cgi script to do something else.

nothing wrong with premade scripts i just find it more fun to DIY it and i can never understand a massive cgi file! i know the basics and worked out a counter system and guestbook on a previous site, it used a load of <iframes> though

PS i dont need to do anything such as place the <!--#include virtual="../ in <script> tags or the header do i?

secondly does it matter if the html is in the cgi-bin for the include tag? may this be why it didnt work? or a problem with xitami?

mlseim
08-16-2006, 05:39 PM
Of course, using SSI or PHP would be the way to go, but I assumed
you wanted to keep your extension the same and use Perl within
your existing page.

You actually could keep the .html extension and still use SSI, if you
associate the .html extension with .shtml (with your server).

KevinADC
08-16-2006, 08:08 PM
secondly does it matter if the html is in the cgi-bin for the include tag? may this be why it didnt work? or a problem with xitami?

Normally that does matter. I already mentioned that in one of my posts, maybe you missed it. But it depends on how you try and reach the html page in the cgi-bin, if directly from the URL that usually does not work because access to static documents in the cgi-bin is normally blocked, only scripts can be accessed from a URL in the cgi-bin. But your scripts can open and read/write to other documents in the cgi-bin.

KevinADC
08-16-2006, 08:11 PM
PS i dont need to do anything such as place the <!--#include virtual="../ in <script> tags or the header do i?

No, just do a search on google for SSI tutorials, SSI is very easy to implement if your server supports it.

disto
08-16-2006, 11:47 PM
right so you suggest to use php or asp to instead of cgi

KevinADC
08-17-2006, 12:47 AM
right so you suggest to use php or asp to instead of cgi

No, I'm not concerned with one approach over the other, that's up to you to decide. If you use PHP you have to convert your html pages into PHP pages. If you use a perl based counter you can use SSI or stick with an <iframe> tag.

disto
08-17-2006, 01:13 AM
right ok would be easier to stick with perl as my pervious site was coded with cgi

mlseim
08-17-2006, 02:30 AM
Find out if you can make all of your .html extensions operate as .shtml,
so you can use SSI without changing extensions. Some webhosts allow that.

In that case, Perl (or "cgi" as you are calling it) would be the way to go.

KevinADC
08-17-2006, 03:20 AM
don't need to change anything if you stick with this approach:

<HTML>
<HEAD>
<TITLE>Homepage</TITLE>
</head>
<body>
This page has been visted <iframe style="border: none; overflow: hidden; width: 60px; height: 25px; padding: 0; margin: 0;" src="../cgi-bin/counter2.pl"></iframe> times
</body></html>

FishMonger
08-17-2006, 03:52 AM
Here's a simple counter script that includes file locking.


use File::CounterFile;
$c = File::CounterFile->new("./COUNTER");

$c->lock;
$id = $c->inc;
$c->unlock;
print $id,$/;
http://search.cpan.org/~gaas/File-CounterFile-1.04/CounterFile.pm

disto
08-17-2006, 09:32 AM
i have used iframes previously and that does work!

i tried saving a shtml file onto my web server and it open the same as a html so im guessing that my server does accept shtml.

i havent done any shtml before ill have to get a book out the library

disto
08-17-2006, 12:04 PM
ah ha!

used the
<!--#include virtual="../cgi-bin/counter.pl?page=index.html" -->

but saved it as a shtml file not html! should i have done this to begin with?

thanks everyone

mlseim
08-17-2006, 01:51 PM
disto ...

You are correct ... the extension using SSI is ".shtml"

Again, thinking you don't want to make any changes to your filenames
or extensions, I was suggesting that you find out if you can process
your SSI using ".html" extension instead of ".shtml"

If you are able to change extensions and that's not a problem,
then switch them all to .shtml

With this whole thread, it just seemed to me that you want to use Perl
scripting in all of the pages that have the extension ".html" and that you
will not (or can't) change extensions.

disto
08-17-2006, 05:46 PM
lol no im quite flexible i just already had a system using <iframe> but i recently changed to a server with fewer limitations and i thought that iframes wernt the best method.
however now i just have to go through the laborious task of adding new content to every page of my site (i redesigned it all, and it needed an update anyway)
changing to shtml isnt too difficult and now the pages automatically open in notepad where as html didnt