Redirect code
Hi,
I need to write a redirect script in Perl. I've never really done anything like that, is there
anybody here that already got the code for a redirect script? I'm no good at Perl.
Basically what I need it to do is take an incoming variable sent to it like:
redirectscript.cgi?XXXXXX
And redirect the surfer to a link based on that variable, such as
http://somedomainname.com/cgi-bin/someotherscript.cgi?itgoeshere=XXXXXX.
The script should have a user defined variable to determine what the
redirection link is, such as:
$link = [url]http://www.somedomainname.com/cgi-bin/someotherscipt.cgi?itgoeshere=$input:"[/url]
So that by moving the $input around (or whatever) I can change the
forwarded link.
For example, if
$link = [url]http://www.mysite.com.com/cgi-bin/example1.cgi?partner=$input&type=sale"[/url]
and the script is sent the variable 12345 like this:
thescript.cgi?12345
then it would redirect the surfer to:
http://www.mysite.com.com/cgi-bin/example1.cgi?partner=12345&type=sale
I would really appreciate if anybody could help me, I'm no Perl expert but I don't think that this should be hard to do.
Greetings,
Emir.
Justin S posted this at 14:36 — 3rd July 2000.
They have: 2,076 posts
Joined: Jun 1999
Try running this program...
#!/usr/bin/perl
use CGI qw/:standard/;
$action = param('action');
if($action eq "1") { &number1; }
elsif($action eq "2") { &number2; }
elsif($action eq "3") { &number3; }
elsif($action eq "4") { &number4; }
else { &showerror; }
sub number1 {
print "Location: [url]http://www.url.com/directory/link.html\n\n";[/url]
exit;
}
sub number2 {
print "Location: [url]http://www.url.com/directory/link.html\n\n";[/url]
exit;
}
sub number3 {
print "Location: [url]http://www.url.com/directory/link.html\n\n";[/url]
exit;
}
sub number4 {
print "Location: [url]http://www.url.com/directory/link.html\n\n";[/url]
exit;
}
sub showerror {
print "Content-type: text/html\n\n";
print "Sorry, there was an error processing your request";
exit;
}
If you look at it you'll see that it's pretty easy to add as many "extensions" as you need. This is how the script works: people go to http://www.url.com/directory/script.cgi?action=1 which will redirect them to the link in sub number1.
Justin Stayton - [email] [icq]
Justin S posted this at 14:37 — 3rd July 2000.
They have: 2,076 posts
Joined: Jun 1999
Oops, looks like vBulletin added [url] and [/url] to the code. Take those out.
Justin S posted this at 14:37 — 3rd July 2000.
They have: 2,076 posts
Joined: Jun 1999
Uhg, can't get this right. It added URL and /URL into the code.
Orpheus posted this at 20:19 — 4th July 2000.
They have: 568 posts
Joined: Nov 1999
I liked the UBB a lot better.
abahta posted this at 23:06 — 4th July 2000.
They have: 58 posts
Joined: Jul 2000
No way!
vBulletin rules!!
emke posted this at 08:43 — 7th July 2000.
They have: 3 posts
Joined: Jul 2000
OK, this is cool. But my problem with redirecting is that I don't know to what URL I'll redirect people to. I mean I don't know what'll be at the end of the URL, something like ?66379. So if I have a short URL that ends with redirect.cgi?66379 I want the script to redirect to the long URL that ends with ?id=66379, the ?something is the same with both URLs.
But as I don't know what'll be at the end, it could be any ?something, I want the script to, and I don't know if this is possible, figure it out from the links URL and automatically redirect to the longer URL with the ?something that is the same as it was in the shorter URL.
I hope that you can understand this.
Is this possible and how can I do this?
Emir.
richjb posted this at 09:52 — 7th July 2000.
They have: 193 posts
Joined: Feb 2000
basically all you want is a system where no matter what they click on ?number always stays the same? like a tracking system for referrals, ect?
Richard
[email protected]
Everyone here has a website. It's just that not all are worth posting (Mine! ).
emke posted this at 12:10 — 7th July 2000.
They have: 3 posts
Joined: Jul 2000
Hi Richard,
Yeah, something like that. The ?numbers users get are dynamically created and the URLs are incredibly long, so I configured the script that I'm using and they get these shorter URLs with the ?something at the end but I figure that I need a redirect script that will take the ?something at the end of the short URLs and redirect to the longer URL. But the problem is that I don't know what they'll get at the end as the ?numbers are dynamically created. So the script needs to take the ?number at the end of the shorter link and than in some way take the ?number and insert it in the longer URLs end and than redirect the user to the longer URL but the ?number of the link at the end of the shorter URL must stay the same in the longer URL that the user is redirected to.
Is this possible?
richjb posted this at 17:58 — 9th July 2000.
They have: 193 posts
Joined: Feb 2000
Problem resolved.
Richard
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.