Home > Archive > PERL CGI Beginners > August 2005 > How do I make two different web pages come up from one CGI?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How do I make two different web pages come up from one CGI?
|
|
| Luinrandir 2005-08-03, 9:59 pm |
| The following does not work....
#!/usr/bin/perl
use strict;
print qq|Content-type: text/html\n\n|;
print qq|<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD><BODY>|;
print qq|1|;
print qq|</body></html>|;
print qq|Content-type: text/html\n\n|;
print qq|<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD><BODY>|;
print qq|2|;
print qq|</body></html>|;
exit;
| |
| Chris Devers 2005-08-03, 9:59 pm |
| On Wed, 3 Aug 2005, Luinrandir wrote:
> The following does not work....
Define "does not work". It seems to work for me:
$ lynx -mime_header http://localhost/test.pl
HTTP/1.1 200 OK
Date: Thu, 04 Aug 2005 00:49:32 GMT
Server: Apache/1.3.33 (Darwin) mod_perl/1.29
Connection: close
Content-Type: text/html
<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD><BODY>1</body></html>Content-type: text/html
<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD><BODY>2</body></html>
$
What are you trying to do? THis may not be what you meant, but it works
just fine. The HTML isn't standards compliant, but it produces results
that will show up in most web browsers.
If you want two different pages, you'll have to insert code that follows
different paths depending on some condition or conditions. That way,
when the page is loaded, the result can vary depending on the input and
other factors; the user will get one version or the other.
If you want one request to produce two separate pages, that isn't
possible. The closest thing I can think of would bee to have a call in
the HTML source that, on load, fires off a second page. Something like:
#!/usr/bin/perl
use strict;
if ($ENV{QUERY_STRING} ) {
print qq|Content-type: text/html\n\n|,
qq|<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD>\n|,
qq|<BODY java script:onload("/path/to/second/url")>\n|,
qq|1\n|,
qq|</body></html>\n|;
} else {
print qq|Content-type: text/html\n\n|,
qq|<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD>\n|,
qq|<BODY>\n|
qq|2\n|,
qq|</body></html>\n|;
}
Or something like that.
--
Chris Devers
| |
| Luinrandir 2005-08-04, 4:01 am |
| I want to create two web pages in two different windows
from one CGI.
Thanks for your input.
----- Original Message -----
From: "Chris Devers" <cdevers@pobox.com>
To: "Luinrandir" <Luinrandir@insight.rr.com>
Cc: "Perl Beginners - CGI List" <beginners-cgi@perl.org>
Sent: Wednesday, August 03, 2005 6:00 PM
Subject: Re: How do I make two different web pages come up from one CGI?
> On Wed, 3 Aug 2005, Luinrandir wrote:
>
>
> Define "does not work". It seems to work for me:
>
> $ lynx -mime_header http://localhost/test.pl
> HTTP/1.1 200 OK
> Date: Thu, 04 Aug 2005 00:49:32 GMT
> Server: Apache/1.3.33 (Darwin) mod_perl/1.29
> Connection: close
> Content-Type: text/html
>
> <HTML><HEAD><TITLE>Seneschals
Report</TITLE></HEAD><BODY>1</body></html>Content-type: text/html
>
> <HTML><HEAD><TITLE>Seneschals
Report</TITLE></HEAD><BODY>2</body></html>
> $
>
> What are you trying to do? THis may not be what you meant, but it works
> just fine. The HTML isn't standards compliant, but it produces results
> that will show up in most web browsers.
>
> If you want two different pages, you'll have to insert code that follows
> different paths depending on some condition or conditions. That way,
> when the page is loaded, the result can vary depending on the input and
> other factors; the user will get one version or the other.
>
> If you want one request to produce two separate pages, that isn't
> possible. The closest thing I can think of would bee to have a call in
> the HTML source that, on load, fires off a second page. Something like:
>
> #!/usr/bin/perl
> use strict;
>
> if ($ENV{QUERY_STRING} ) {
> print qq|Content-type: text/html\n\n|,
> qq|<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD>\n|,
> qq|<BODY java script:onload("/path/to/second/url")>\n|,
> qq|1\n|,
> qq|</body></html>\n|;
> } else {
> print qq|Content-type: text/html\n\n|,
> qq|<HTML><HEAD><TITLE>Seneschals Report</TITLE></HEAD>\n|,
> qq|<BODY>\n|
> qq|2\n|,
> qq|</body></html>\n|;
> }
>
> Or something like that.
>
>
>
> --
> Chris Devers
>
| |
| David Dorward 2005-08-04, 5:00 pm |
| On Wed, Aug 03, 2005 at 10:45:35PM -0700, Luinrandir wrote:
> I want to create two web pages in two different windows
> from one CGI.
Each request gives one file, that's how HTTP works. You will need at
least two requests, with the script running twice (or two scripts
running once each).
You can use JavaScript to spawn a second window, although it might be
blocked by popup blockers (the specifics of such a solution are rather
off topic for this list though, so I'll suggest you look elsewhere if
you want to go down that path).
--
David Dorward http://dorward.me.uk
| |
| Wiggins d'Anconia 2005-08-04, 5:00 pm |
| David Dorward wrote:
> On Wed, Aug 03, 2005 at 10:45:35PM -0700, Luinrandir wrote:
>
>
>
> Each request gives one file, that's how HTTP works. You will need at
> least two requests, with the script running twice (or two scripts
> running once each).
>
> You can use JavaScript to spawn a second window, although it might be
> blocked by popup blockers (the specifics of such a solution are rather
> off topic for this list though, so I'll suggest you look elsewhere if
> you want to go down that path).
>
Just to be thorough, not specifically because I like them, I will
mention frames. Frames are an easy way to give the appearance of two
requests (because there are actually three) without many client side
limitations. Most *graphical* browsers support frames these days.
And though I don't yet have experience with it I suppose you could look
into Ajax.
http://danconia.org
|
|
|
|
|