Need a re-direct script.....

Hi,

Easy question for anyone that hangs around Perl sites.

What I want is to put a few links to a different site on some pages I have, but for the links to be sent through a script on my site, no need even to log the clicks - just to send the user to the given site.

So the links on my page would look something like this:

<A HREF="../cgi-bin/myscript.pl?http://anothersite.com/page.html">Test</A>

Don't ask why I just don't send them there if I'm not logging it - just something I need to do. This could probably be done in just a few lines of code I guess, but just haven't got the time....don't need anything fancy, but it MUST work properly.

Thx in advance,
D
LVL 1
dgb001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guadalupeCommented:
Maybe a little overkill but:

#!/usr/local/bin/perl

require ("/virtual/ar/robots/lib/funcLib.pl");
$LOG_FILE  = sprintf "redirect%s.log", &CalculaFechaActual( $YYYY );


#Parse form variables
if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
          read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
      {
          $temp = $ENV{'QUERY_STRING'};
    }

@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}

if (($fields{url} ne "") && ($fields{url} =~ /http:\/\//))
{
print "Location: $fields{url}\n\n";
exit;
}



      


#Default if not found
open (LOG, ">>/virtual/ar/cgi-data/redirect.log");

print LOG "Error de syntax en $ENV{'HTTP_REFERER'}\n";

close LOG;

#Redirect to default due to bad URL passed to script
print "Location: http://XXXXXXXXXX\n\n";


Carefull to change the info about the error log and also the default which is used if the url is badly passed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgb001Author Commented:
Hmmm!! Well, if you can tell me where I can download the whole setup then I'll be a bit more inclined to give you the points. As it is, without knowing where "virtual/ar/robots/lib/funcLib.pl" is meant to be, and what it does, and also the fact that I did say that I didn't need logging code then, well...I'm still left needing something that works the way I want. The code could probably be done in no more than 10 lines, I just haven't got the time.

Look forward to your updated response.
D
0
guadalupeCommented:
#!/usr/local/bin/perl


#Parse form variables
if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
          read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
      {
          $temp = $ENV{'QUERY_STRING'};
    }

@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content =~ s/%00//g;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}


if (($fields{url} ne "") && ($fields{url} =~ /http:\/\//))
{
print "Location: $fields{url}\n\n";
exit;
}



#Default if not found
print "Location: http://www.uol.com.ar\n\n";
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

guadalupeCommented:
Sorry, you need to change the default and the comment is missleading
It defaults if the passed url is blank or lacks "http://" (It is necessary to put http:// or it will not work!).
0
dgb001Author Commented:
Ok, give me a little while to play with it and I'll get back to you.

Thx,
D
0
dgb001Author Commented:
Yep, that's great - thx. D
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.