FireBird34 has asked for the wisdom of the Perl Monks concerning the following question:

There are several reasons I want this for, but the main is in tracking who is visiting what page. I am going to write a script, saving the necessory info. into a file, reguarding who visited what content. However, I have no idea how to call a CGI scipt from an HTML (SHTML?) document. I've tried a variety of methods, but can't do it thus far. I *should* have SSI, but in case I don't (don't know how to test this really, n00b at this in a way still), both SSI and regular calls would be helpful. Thanks.

Replies are listed 'Best First'.
Re: Calling a script onto an HTML doc.
by thpfft (Chaplain) on Oct 24, 2002 at 01:40 UTC

    with ssi from an shtml file:

    <!--#include virtual="/cgi-bin/sinister_tracking_script.pl"-->

    and in sinister_tracking_script.pl:

    my $page = $ENV{HTTP_REFERER}; # iirc

    or more simply (unless you want to take the opportunity to generate the html for some of the page) and without requiring SSI:

    <img src="/cgi-bin/creepy_bug.pl">

    and from creepy_bug.pl you can retrieve the page address in the same way, log it and then either return a standard image file, print a counter for old times sake, or just not bother. Note that this method is vulnerable to browser caches and proxies and so on: best to add a unique identifier to the image address each time, so that the browser definitely asks for it. and yes, you can set a cookie while returning an image file, which you can't with ssi-included html.

    Don't use this technique on remote pages, btw, especially not with very small images. People will make wild accusations.

    ps. google is your friend.

      Thanks for the help =) I'll post back here if I can't get it working (unlikely, but you never know what us n00bs can mess up =)).
Re: Calling a script onto an HTML doc.
by rruiz (Monk) on Oct 24, 2002 at 01:55 UTC

    Hi, God bless you.

    To appropriately help you, we need to know what your webserver is and the running OS. However this may be a little off topic. Also you may want to look at your webserver documentation as it may have the information you are looking for in its log files.

    I, for example, use the Apache web server, and to call a cgi script from a SSI page, I could use:

    <!--#include virtual="/cgi-bin/script.pl" -->

    or,

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

    Depending if I am writing for the intranet (use first form, I control the webserver), or for the internet (second form, required by host).

    HTH
    rruiz

      I am using the Abria Merlin server -- uses Apache server software, along with PHP/MySQL and other addons (not into PHP/MySQL really atm though). Also, Win98. I would prefer to be under Linux, but my E-Card is to outdated, and messing with drivers gave me a headach.
Re: Calling a script onto an HTML doc.
by true (Pilgrim) on Oct 24, 2002 at 10:47 UTC
    To test and see if you're webserver
    is including SSI, try the following:
    Put some SSI commands in test.shtml.
    Then try and view test.shtml in a browser.
    You should see responses from the echos.
    <title>SSI Test-Do i have Server-Side Include?</title> My IP Address is:<!--#echo var="REMOTE_ADDR"--> This page is:<!--#echo var="DOCUMENT_NAME"-->
    SSI can be pretty draining so apache leaves it out by
    default. Here's what a ssi-enabled www folder should
    look like in apache httpd.conf file.
    <Directory /home/user/domain/www/> Options Indexes Includes AddType text/html .shtml AddHandler server-parsed .shtml </Directory>
    this works on apache 1.3.26
    P.S. As you can see with apache, ssi pages don't have to be called .shtml.
    To be really be sure whether SSI is running AND you are
    connecting to it properly, check your apache conf file.
    Apache SSI Help

      It would be safer to use

      Options +IncludesNOEXEC

      This way you disable execution of local commands, as explained in Apache SSI documentation:

      Server-side includes are permitted, but the #exec command and #exec CGI are disabled. It is still possible to #include virtual CGI scripts from ScriptAliase'd directories.

      Ciao, Valerio

        Thanks for the help! I was able to configure it, but it wouldn't take effect. Finally got fed up, and shut down the computer. Came on the next morning, and it worked... no brainer, I know. Forgot to reboot. Thanks again for the help!