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

Is it possible to call a cgi script from the index.html file so that the output shows up on the home page. I have a script that makes a database call and I want those result on my home page.

Replies are listed 'Best First'.
Re: Running a cgi script from index .html
by Ovid (Cardinal) on Mar 07, 2003 at 17:45 UTC

    If your admin will not allow you to use the exec version of SSIs (many will not due to security implications), you can make the CGI script your home page. Also, you can use a meta tag to redirect the user to a CGI script. While SSI is a great lightweight alternative, you will get more control just by having the CGI script create the entire page.

    <meta http-equiv="refresh" content="2;URL=http://www.yoursite.com/newp +age.htm" />

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Running a cgi script from index .html
by dws (Chancellor) on Mar 07, 2003 at 19:56 UTC
    Is it possible to call a cgi script from the index.html file so that the output shows up on the home page?

    On the chance that you phrased your question a bit too narrowly, I'll answer the broader question "Is it possible to invoke a CGI script instead of index.html?"

    Yes. Details for how to do this depend on what web server you're using. Apache and IIS can both be configured with a list of names to try to figure out how to handle   http://www.example.com/ index.cgi can be on that list. Assuming you've also configured the web server to execute CGIs, index.cgi will get invoked no other file on the list is found first.

    With Apache, you can arrange, on a per-directly basis, to have .html mean CGI. Consult the Apache docs.

Re: Running a cgi script from index .html
by jasonk (Parson) on Mar 07, 2003 at 17:18 UTC

    If your webserver supports it, yes. Apache has Server Side Includes (SSI), which allow you to have html comments that the server replaces with real content, by doing something like this:

    <!--#exec script="myscript.cgi" -->

    But this really isn't a perl question, so if you aren't using Apache, or this doesn't help, you should really ask in a forum related to your web server software.

Re: Running a cgi script from index .html
by fruiture (Curate) on Mar 07, 2003 at 17:21 UTC

    TIMTOWTDI. Do you have SSI available? Enable them for your index.html and use some 'exec cgi' command. Or just make index.html a Perl Program and tell the webserver it is one. Do you have a possibility like mod_rewrite? Just rewrite index.html to whatever script URI you want.

    You see, this is more a problem of how to configure your server, not neccesarily a Perl problem. Anyways, I'm sure the Perlmonks can help you if you tell us what webserver you're using.

    --
    http://fruiture.de
      I am using Apache server.

        That's good. The documentation is available online ;)

        It's likely that Ovid is right and you cannot configure anything at all, but if you can, I think the following will be configurable as it is no danger for the server.

        # .htaccess file <Files index.html> SetHandler cgi-script </File>

        Now you can simply put a Perl Script in "index.html" and it will work.

        If you only want it to be index.html because it is the directory index, there's a better method:

        DirectoryIndex index.cgi index.pl

        You don't need any index.html now, just create index.cgi (or index.pl if you like) and it will be directory index.

        --
        http://fruiture.de