Forum Moderators: coopster

Message Too Old, No Replies

Looping Problem on Redirects in IE

         

popzzz

7:23 am on Mar 11, 2008 (gmt 0)

10+ Year Member



I am trying to eliminate the original referrer and hide my affiliate
links (obviously) when called by example.com/index.php?a=topic
(in this example) with this code:

<?PHP
$a = $_GET['a'];
if ($a == "") {$link = "http://example.com/index2.php";} // Default Blank
if ($a == "topic") {$link = "http://example2.com/aff_link";}
header("refresh: 0; $link")¦;
exit();
?>

(pipe broken by forum)

The problem is it works perfectly in firefox (2.0.012) and has a blank
referrer at the affiliate end as intended, but in Internet Explorer
(7.0.6000) it 'loops' and tries to reload continuously.

Does anyone know how can this be modified to remedy the looping in IE please?

Thank you in advance,
popzzz

popzzz

7:46 am on Mar 11, 2008 (gmt 0)

10+ Year Member



CORRECTION to previous post:

The pipe symbol does NOT belong in the code.

Correct code is:
<?PHP
$a = $_GET['a'];
if ($a == "") {$link = "http://example.com/index2.php";} // Default Blank
if ($a == "topic") {$link = "http://example2.com/aff_link";}
header("refresh: 0; $link");
exit();
?>

Sorry for any confusion and thanks again,
popzzz

PandaM

12:32 pm on Mar 11, 2008 (gmt 0)

10+ Year Member



I think it should be like this:

header("refresh: 0; url=$link");

popzzz

3:41 pm on Mar 11, 2008 (gmt 0)

10+ Year Member



Hi PandaM, (and thanks)

Your suggestion unfortunately adds the url= to the url as in:
/a/url=http://example.com which results in a 404 not found.

popzzz

jatar_k

4:48 pm on Mar 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



header('Location:' . $link);

popzzz

5:23 pm on Mar 11, 2008 (gmt 0)

10+ Year Member



Hi jatar_k! (and thanks)

That stopped the reloading and now works but has
the undesirable result of passing the referrer in IE.

FF does NOT pass the referrer.

popzzz

jatar_k

7:45 pm on Mar 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe because the page has no output? Foolish as it should still show your intermediary page as the refere

you could test showing a page and outputting a meta refresh and see if that works. ugly though

popzzz

8:27 pm on Mar 11, 2008 (gmt 0)

10+ Year Member



Thanks again jatar_k,

Let me try to reclarify ...

I am trying to eliminate referrer from site A showing up on site C.
Would prefer site B as referrer or simply NO referrer at all.
as example:
A > B(redirect) > C = B or blank referrer

The php script above is for multi links. (php on site B)
.htaccess converts the 'topic' into a variable for the php to select the outgoing link to redirect to.
i.e. example.com/topic is rewritten to example.com/index.php?a=topic to be used by the php script above.

Net result ... one file to edit with multi links, and (hopefully) no reference back to site A on site C.

I hope this made sense.

popzzz

3:49 am on Mar 12, 2008 (gmt 0)

10+ Year Member



Anyone have any ideas?

PandaM

1:41 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



I mean use
header("refresh: 0; url=$link");

instead of
header("refresh: 0; $link");

I've tested on both firefox and IE, it redirect without any error.

jatar_k

1:45 pm on Mar 12, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yes, it's called a redirect script, it's used for tacking outbound clicks and/or scrubbing referers, I know exactly what you mean.

my last post was directed to the fact that you mentioned IE was keeping the original referer even though you passed it through the script. I was saying that output may stop this.

put your script on B and keep echoing the referer on C. Play around with the script on B and see what makes a difference.

popzzz

12:32 am on Mar 13, 2008 (gmt 0)

10+ Year Member



Hi and my apologies to PandaM and jatar_k!

Not sure why it didn't work before but this time it works perfectly. (as it should have the first time)

Redirects as it should with no referrer in both FF and IE.

Thanks again everyone!

popzzz

popzzz

4:37 am on Mar 13, 2008 (gmt 0)

10+ Year Member



After further testing, Opera 9.26 passes site B (script) as a referrer to site C.
Which is OK with me.

HTH

popzzz

7:21 pm on Mar 31, 2008 (gmt 0)

10+ Year Member



Now a new problem has surfaced:

If someone enters a bogus or non-existent name that does not pre-exist in the file such as
example.com/index.php?a=bogus the script loops and trys to reload continuosly.

I've tested all my limited knowledge allows, but can't seem to come up with a solution.

Can anyone shed any light on this?

Thank you in advance,
popzzz

PHP_Chimp

9:50 am on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$a = $_GET['a'];
if ($a == "") {$link = "http://example.com/index2.php";} // Default Blank
[b]elseif[/b] ($a == "topic") {$link = "http://example2.com/aff_link";}
[b]else[/b] {
// do something.
}
header('refresh: 0; url="$link"'); // or whatever code you are using
exit();

I guess that the else may well be the same as the if stetement, so you could write this as -

$a = $_GET['a'];
if ($a == "topic") {$link = "http://example2.com/aff_link";}
else ($a == "") {$link = "http://example.com/index2.php";}

Also remember that the referer is part of the $_SERVER [uk.php.net] array, so you can alter it to whatever you like.

popzzz

12:39 pm on Apr 1, 2008 (gmt 0)

10+ Year Member



Hi PHP_Chimp! (and thanks)

Hmmmmm ...

I took the
if ($a == "") {$link = "http://example.com/index2.php";} // Default Blank
from the top and moved it to the bottom just as you have it as
else ($a == "") {$link = "http://example.com/index2.php";} // Default Blank
and it returns
Parse error: syntax error, unexpected '{'

The parse error would indicate a mismatched pair from what I can determine but have checked closely and all pairs are matched.

Stuck again ....

For clarity the new code looks like:
$a = $_GET['a'];
if ($a == "topic") {$link = "http://example2.com/aff_link";}
else ($a == "") {$link = "http://example.com/index2.php";} // Default Blank
header("refresh: 0; $link");
exit();

Am I missing something?

Thank you in advance,
popzzz

PHP_Chimp

1:33 pm on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Durrrrrr...my mistake. The else statement doenst take any arguments, as it is what happens when the if/elseif statements dont get executed. So you can remove the bit I have stuck in comments.
That should get rid of the problem...hopefully ;)


$a = $_GET['a'];
if ($a == "topic") {
$link = "http://example2.com/aff_link";
}
else [b]/* ($a == "") */[/b] {
$link = "http://example.com/index2.php"; // blank page
}
header("refresh: 0; $link");
exit();

popzzz

2:02 pm on Apr 1, 2008 (gmt 0)

10+ Year Member



Hi again! (and thanks)

That got rid of the error however it now sends any/everything to the index2.php whether it is supplied in the list or not.

It's like it doesn't see the if matches at all now and goes straight to the else?
(which makes no sense to me)

Still stuck?

Thank you in advance,
popzzz

PHP_Chimp

7:12 pm on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok try this -

if (isset($_GET['a'])) { // check to see if a is set
$a = $_GET['a'];
}
else {
$a = ''; // if not set then set it to blank string
}
if ($a == "topic") {
$link = "http://example2.com/aff_link";
}
else {
$link = "http://example.com/index2.php"; // blank page
}
header("refresh: 0; $link");
exit('Testing, should not be shown');

I dont know if this was what you problem was, but this should make sure that there is an $a variable.
I have also put a message in the exit, so you can see if you are getting a blank page from your index2 redirect or a blank page from the exit statement.

Hope that works for you.

popzzz

2:13 am on Apr 2, 2008 (gmt 0)

10+ Year Member



Hi again! (and thanks)

Back to the same as before ... sends any/everything to the index2.php whether it is supplied in the list or not.

It's like it doesn't see the if matches at all now and goes straight to the else?
(which makes no sense to me)

Still stuck?

Thank you in advance,
popzzz

PHP_Chimp

9:50 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you run -

echo '<pre>';
print_r($_GET);
echo '</pre>';

So that we can see what the GET array actually is?

popzzz

1:40 pm on Apr 2, 2008 (gmt 0)

10+ Year Member



Hi again! (and thanks)

<pre>Array
(
)
</pre>

Thank you in advance,
popzzz

PHP_Chimp

4:00 pm on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lol then that big blank space between the <pre> tags is your problem...there is no $_GET array. So the code cant work.

I take it that index2.php is the page where you are running this code? As if you redirect people who dont have $_GET['a'] = topic then you will get a continual loop of redirection. Try this as hopefully it will explain what is going wrong -


if (isset($_GET['a'])) { // check to see if a is set
$a = $_GET['a'];
}
else {
$a = ''; // if not set then set it to blank string
}
if ($a == "topic") {
header("refresh: 0; url=http://example2.com/aff_link");
}
else {
die('You dont have $a == "topic"...naughty boy');
// $link = "http://example.com/index2.php"; // blank page
}
// header("refresh: 0; $link");
exit('Testing, should not be shown');

I suspect that this is the problem, but if it isnt then what is the url you have been using to test the code on that page?
Please remember to stick in example.com ;)