CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Using require to redirect a cgi script



Jun 22, 2012, 3:39 PM

Post #1 of 5 (2654 views)
Using require to redirect a cgi script Can't Post

I have a situation where I am calling a single signon.cgi script with information posted to it.

What I need to do is, if the parameter is X, I need to execute custom_signon1.cgi, if the param passed is Y, I need to execute custom_signon2.cgi.

I've found that if I change custom_singon1.cgi to, I can check the param, and then do:

if(x) {
require ""
elsif(y) {
require "

What happens seems to be exactly what I want. the CGI parms are still part of the namespace, so the modules I include can re-read the cgi vars and use them.

I would like some opinions on this method, I dunno if there is a better way. The brute force way is to simply generate an html form with hidden params and then post to the file I want to redirect to.

(This post was edited by srhadden on Jun 22, 2012, 3:40 PM)

Veteran / Moderator

Jun 22, 2012, 5:13 PM

Post #2 of 5 (2648 views)
Re: [srhadden] Using require to redirect a cgi script [In reply to] Can't Post

You haven't provided enough info for us to say if what you're doing is the proper or best approach. We would need to know what your scripts are doing.

If you need to maintain state between cgi scripts, the normal approach is to use sessions.


Jun 24, 2012, 4:26 PM

Post #3 of 5 (2603 views)
Re: [srhadden] Using require to redirect a cgi script [In reply to] Can't Post

I dont think thats is the best way, it could work and then break later...

I would require both modules in and then compare what ever then, based on that use what ever sub from the modules... are the modules really large ?? if they are you can import only sub's from them if need be rather then everything...

also use the code blocks provided...

do these modules have the same name sub's?

Heres and example of what im talking about....

use strict; 
use warnings;
use CGI;
require "";
require "";

my $cgi = new CGI;

my $user = params->{'UserName'};
my $password = params->{'PassWord'};
my $date_time = params->{'date_time'};

if(x) {
#use sub from
elsif(y) {
#use sub from

(This post was edited by wickedxter on Jun 24, 2012, 4:29 PM)


Jun 24, 2012, 6:19 PM

Post #4 of 5 (2595 views)
Re: [wickedxter] Using require to redirect a cgi script [In reply to] Can't Post

Thanks for the replies so far. I appreciate your time very much.

I use to have a single cgi script that managed two different types of logins. But now I need to separate out that into two separate cgi files. So I have two .cgi files that have basically the same set of function calls.

When the user logs in, it calls the wrapper script, signon.cgi. WHat I need to do is now decide which script to call. signon1.cgi or singon2.cgi.

I currently use require. Based on the cgi params passed into the wrapper, I require signone1.cgi or signon2.cgi.

This is for a fairly old legacy system before Session was even around and is using an older perl. So I'm limited to what I can do.

I am using require and it works. If I thought this would be a problem I probably would write the wrapper signon.cgi to do the following.

1. Generate html with a form and loop through all passed in params. The form will have all hidden text fields. Then the generated html will send a post in the <body onload="signon1.cgi or signon2.cgi">. So it is the long archaic way to re-send parameters between cgi calls. I am not even sure Session is even on these systems.

What I didn't understand was why the require worked. The wrapper script creates a CGI object and processes the params. Then it requires signon1.cgi or signon2.cgi. These are stand-alone scripts, with their own set of headers and create their own cgi object to process params. I was surprised that using require seemed to include the file in it's own namespace. This is just from my lack of indepth knowledge of require. I will study that in the meantime.


Thanks again.

(This post was edited by srhadden on Jun 24, 2012, 6:22 PM)

Veteran / Moderator

Jun 25, 2012, 8:28 AM

Post #5 of 5 (2563 views)
Re: [srhadden] Using require to redirect a cgi script [In reply to] Can't Post

I have two .cgi files that have basically the same set of function calls

Wrong approach. Write a true module that exports its subs and simply call whichever sub you need.

What version of perl are you using?

If you can you post your code, we might be able show you better methods.

(This post was edited by FishMonger on Jun 25, 2012, 8:29 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives