View Full Version : Can't get JS to redirect properly, please help.

12-19-2004, 12:24 AM

I bought this neat script that redirects to different product sites, but the problem is that it isn't working exactly as it should. I'll be as detailed as possible and if you have any ideas how to fix it, please let me know.

Let's assume that the name of the script is "p.cgi". The way that it works is you upload a text file named "redirects.txt" to the same directory where the p.cgi is located.

The contents in the "redirects.txt" looks like this...


Now, if you go to http://www.mydomain.com/p.cgi?p=1, the "p=1" should tell it to look in the text file at the number "1" and redirect to the domain after the "|" in the number 1 postion, which is http://www.mydomain.com/page1.html.

If I go to http://www.mydomain.com/p.cgi?p=2, then it should redirect me to http://www.mydomain.com/page2.html... and so on.

The good news is that when I go to product 1 (p=1), it takes me to the "page1.html" like it should. But the bad news is that when I specify any other products, like p=2 or p=3, even though they are on the "redirects.txt" file, it does not recognize them and simply takes me straight to the main domain page at http://www.mydomain.com... which is specified as $mainurl in the script.

Here's parts of the script to help you see how it's written and where I think the problem lies...

First, the script opens like this...

#### The file where your redirect page urls will be saved #####

$redirs = "redirects.txt";

#### Your main website url ####

$mainurl = "http://www.mydomain.com";

That's pretty easy to figure out. Now, the part where I think the problem lies is this one...

$prod = $FORM{'p'};


open(LIST, "<$redirs");
@list1 = <LIST>;

foreach $linea (@list1) { chop($linea); @tempa = split(/\|/,$linea);

if($tempa[0] eq $prod) { $found = 1; }

if($found eq "1") {
print $query->redirect(-url=>"$tempa[1]");
exit; }

else {
print $query->redirect(-url=>"$mainurl");

Based on what I have described, can you figure out what part of this script I can fix so that it works properly.

Keep in mind that when I enter the "p=1" in the link, it works perfectly, but if I go to the links where I enter "p=2" or "p=3", then for some reason, the script does not recognize it and reads it as if there is nothing after the "p.cgi" and simply goes to the "else {", which means it redirects to the "$mainurl" (http://www.mydomain.com).

Any ideas and insights to fix this will be greatly appreciated.


Jaime Ojeda

12-19-2004, 02:22 AM

This isn't a Javascript, isn't it? It looks more like Perl... do you know by any chance how to fix a Perl script?

Sorry for the mis-post.


Jaime Ojeda