We help IT Professionals succeed at work.

Script to forward input to another CGI script...?

elpmet
elpmet asked
on
I'm trying to write a CGI script in Perl, that just forwards client's request to an actual remote CGI program that does the actual work. And it also receives the resulting data from the remote script. Can we do this?

For example,

1) The front-end HTML (say, "front.html") sends Name and Email to a script (which I'm trying to write;  filename is, say, "middle.cgi").

2) This script ("middle.cgi") confirms/tests the inputs, and forwards to the remote CGI script (say, "end.cgi").

3) "end.cgi" processes what it received from "middle.cgi" and dumps its result back to "middle.cgi".

4) "middle.cgi" dumps a simple confirmation message to the client browser.

I'm wondering if you could write me a basic, but working script ("middle.cgi") as a head-start.  Thanks a million for your help!  (I'm running Linux on my box)

elpmet.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
#### front.cgi:

#! /bin/perl
use CGI;
@result = `path/to/middle.cgi`;
# process result here
print header();
print "message";


#### middle.cgi:

#! /bin/perl
use CGI;
@result = `path/to/end.cgi`;
# process @result here
print "middle result";


#### end.cgi:

#! /bin/perl
use CGI;
# process here
print "end result";


# but all above sounds like a bad solution,
# I recommend to write a "sub middle" and a "sub end" inside frint.cgi, which then calls these subs

Commented:
If your remote CGI script runs on a web server and is only accessible through HTTP, look into lib-www-perl (LWP) (http://www.linpro.no/lwp/).   LWP::Simple should be all you need.

Commented:
yes, and you can find small working examples at the cpan website

Author

Commented:
ahoffmann,

Thanks for your help.  But the "front.html" script is a simple HTML file which sends a request to the "middle.cgi" script which then simply forwards what it received to the "end.cgi" which dumps the result back to "middle.cgi".  Each script is located on a different web server.  Can we still do this without using network modules?


nettrom, and bebonham,

Thanks for your suggestion, but is there any other way without downloading the utilities?  (or can you point me to an exact location for the module?  I went to the site, but I couldn't find documentation on how to use it either.  Also, can I still install that without having the root access?  I'm sorry for being a newbie in unix/perl)

Commented:
You should be able to run modules without having to install them.  Perl will, IIRC, also look for modules in the current working directory (in other words, where the script is run from).  It's also possible to manipulate Perl's list of directories to search for modules at run-time, but that topic is beyond my current knowledge of Perl.

Perl can of course access system tools, so you could use lynx or wget if either of those are installed on your system.  To retrieve the source of a document through lynx you call it with 'lynx -source URL', so in Perl you could do:

my($url) = "http://www.yahoo.com";
open(MYURL, "lynx -source $url|" or die "Unable to open file: $!";
my(@content) = <MYURL>;close(MYURL) or die "Unable to close file: $!";then you have the content of the document found in the array @content.

Author

Commented:
Thanks, folks, and bebonham,

I've printed out the doc and am going to write a test program to see how it goes.  I will come back soon.  Thanks for for your help!

elpmet.

In the meantime, I have another CGI question as follows (please help if you know anything about it...): http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cgi&qid=20187827
CERTIFIED EXPERT

Commented:
elpmet,

Did you get the solution you were looking for?

If so, please delete this question & free up your points, or award the points to the answer you found most useful.

Thanks,
CERTIFIED EXPERT

Commented:
elpmet,

You have the following 2 questions open in the "CGI Programming" topic area.
These questions have been open for more than 2 months now.


http://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20187827 (09/25/01)
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20186615 (09/23/01)

Please go ahead and close these questions at the earliest.

Thanks.
CERTIFIED EXPERT

Commented:
elpmet,

                     Did you get the solution you were looking for?

                     If so, please delete this question & free up your points, or award the points to the answer you found
                     most useful.

                     Thanks,
Points reduced for split.  Comment from expert accepted as answer.  bebonham, look for your question in this topic area.

Computer101
E-E Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.