Forum Moderators: coopster & phranque

Message Too Old, No Replies

Redirecting post data with PERL

         

Drewser

5:00 pm on Jun 16, 2003 (gmt 0)

10+ Year Member



How do redirect post data? I have a cgi script that sends in post data and I need to redirect it to another script with the data intact.

REDIRECT (as it is now):
print "<META http-equiv='refresh' content='0;URL=jollyo.cgi'>";

jatar_k

1:02 am on Jun 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<disclaimer>not a perl guy</disclaimer>

I think people have mentioned using LWP [perldoc.com] for these types of operations.

Hopefully someone can come flush out the info. :)

cminblues

9:40 am on Jun 17, 2003 (gmt 0)

10+ Year Member



If you're on an Apache server, it's infinitely better to use ModRewrite, _without_ external redirs.
i.ex.

RewriteEngine On
RewriteRule ^.*\/your_regex_here\.cgi$ /your_path/jollyo.cgi [L]

This way, all happens without redirects, both server & client side.

Note: you can do this also if you've only a non-privileged account, by using .htaccess.

But if the 2 CGIs are on different servers.. then you need maybe to mimic 100% the behavior of a standard GUI browser. ;)

In other words:
1] user X posts to server A
2] server A posts to server B, acting as 'human-using-IE'
3] server A gets right response from server B
4] server A give response to user X
5] user X gets the response from server A
6] user X has no way at all to know that data, in fact, comes from server B.
7] server B has no way at all [note: at all if server A goes through a proxy i.ex..] to know that data,
in fact, comes from a machine.

It's this your scenario?

BCMG_Scott

2:18 pm on Jun 17, 2003 (gmt 0)

10+ Year Member



Let me see if I have this correct? You have a form that calls a cgi script - it sends post data to the cgi script. You then want to call a second script and pass that post data to it? Is that correct?

If so you can do it a few ways.

First option is if you have not issued a print "Content-type:text/html\n\n"; you can use the print "Location:http://yourdomain.com/cgi-bin/second.cgi?data1=value1&data2=value2";

problem of course is that the post values now are get values.

Second option, if the script is on the same server as the first you can call and exec() or system() command and run it that way - check your perl man pages for those or go to perldoc.com for more detail on those commands.

Third option as jatar_k mentioned is to use LWP or another perl mod (see search.cpan.org for more mods).

Scott Geiger