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

Ok, does any one know if you can run a perl script from an html page, any way I have a small script called members.cgi. I want it to load on my index.html page. what it does it ckecks for 3 cookies. if it finds the cookies it greats them, if it doesn't it displays a form. with Name, Email, and password. that they can fill it and become a member. Thanks Joe

Replies are listed 'Best First'.
Re: Perl and HTML
by enemyofthestate (Monk) on Jul 06, 2005 at 14:59 UTC
    If you enable SSI in Apache (assuming you use Apache) you can include an executable program using include virtual:
    <!--#include virtual="/cgi-bin/myscript.cgi" -->

    You will have to load mod_include, turn on "Option Includes" in the relevant directory and add/edit in httpd.conf:

    AddType text/html .shtml AddOutputFilter INCLUDES .shtml

    I think that's about it but see http://httpd.apache.org/docs-2.0/howto/ssi.html for a more complete tutorial.

Re: Perl and HTML
by kwaping (Priest) on Jul 06, 2005 at 15:03 UTC
    As others have already said, you can check with your website's hosting company and see if you can use Server Side Includes (SSI).

    There are some other alternatives. You can create an index.cgi to read in your HTML file, swap out some targets for the dynamic information, then spit it out to the web browser. You can also get sophisticated and use a templating module like Template::Toolkit.
        SSI won't do the trick, because SSI doesn't give you the cookies information.
        Hi Joost,

        I've seen that statement several times now. Have you looked at $ENV{HTTP_COOKIE} in an included cgi?

        Are you talking about cookies and CGI.pm? If that isn't what you mean, would you explain in a little more detail?

Re: Perl and HTML
by xorl (Deacon) on Jul 06, 2005 at 14:40 UTC
    I haven't done this with Perl, but with PHP if you have server side includes enabled in Apache, you can include a PHP file which will excute its code when the html page is fetched. I would guess you should be able to set up apache to do something similar with a Perl script.

    As far as checking for cookies, the CGI.pm has something to deal with cookies CGI::Cookie or you can just search CPAN for "Cookie" here Cookie

      Can you not just create an overall script that gets passed some information on whether the cookies have been found or not. That way you can just include a simple statement that checks to see if the value is true or false then executes a given script based on the answer, say:
      my ($boolean) = @_; if($boolean eq 1) { #call script here } else { #call HTML page here }

      Hopefully this way you will be able to troubleshoot alot easier when you get a probelm with your code, where you can find the problem a much quicker - you know which script is causing the problem.

      MonkPaul.

        Ok, sorry, no one has the right idea. I don't want to call a html page from a cgi script. I want to call a cgi script from a HTML page. It's a short script. it does 2 things. when the user views my index.html page. the cgi script runs. It checks for to cookies. if it finds them, it says welcome back user. if it doesn't it then displays a form, so if they wanted to. they couls sign. or some thing lime that.
      perhaps a little off-topic, but if you really really want it, you can use embperl to code perl in html, the way php is used as well

      "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      Ok, you don't under stand. I already have the script completed . I just want to know how I can run it from with in a HTML page. If all else fails. Again. how do I run a cgi script from a HTML page Thanks
Re: Perl and HTML
by shiza (Hermit) on Jul 06, 2005 at 16:20 UTC
    As said above, an SSI will do the trick. I would suggest taking a look at HTML::Template. I think it is good practice to separate your logic from your UI (HTML in this case). HTML::Template makes this very easy.
Re: Perl and HTML
by data64 (Chaplain) on Jul 06, 2005 at 19:55 UTC

    Based on your responses to the other posts in this thread, let me try to summarize your question.

    When someone requests the page, you want to check for presense of cookies and redirect the user to a registration/login page.

    The way cookies work is, if the browser has any cookies for that domain then they would be included in the original request. So you do not need to do the return trip thing that you are asking about. Use cgi.pm to check for cookies and issue a redirect if none a found.