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. | [reply] [d/l] [select] |
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. | [reply] |
|
|
open HTML,"<","/path to html" or die "Can't open html: $!";
print "Content-type: text/html\n\n",<HTML>;
close HTML
At the end of the script. For a more general solution, see HTML::Template (or one of the other template modules) and CGI::Application. Or see Web Applications for a possibly helpful thread.
| [reply] [d/l] |
|
|
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?
| [reply] [d/l] |
|
|
|
|
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 | [reply] |
|
|
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.
| [reply] [d/l] |
|
|
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.
| [reply] |
|
|
|
|
|
|
|
| [reply] |
|
|
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
| [reply] |
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. | [reply] |
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.
| [reply] |