Page 1 of 1

header php function challenge

Posted: Fri Mar 03, 2006 4:48 pm
by vidya
I'd like to use the header php function
to redirect to any given url.

But I ran into a problem. Check this:
My link.html code is simply this:

<?php
$link = $_GET['pg'];
header("Location: $link");

?>
<html>
<p><a href="<?=$link?>">Click Here</a></p>
</html>


Oughta work, eh?
But when I use this URL:
http://www.americanprogressaction.org/s ... ct=2026855

in a call like this:

http://www.webwisesage.com/link.html?pg ... ct=2026855

it gets a bad page address, whereas the page at the url is fine!

Any ideas?

...Vidya
http://www.webwisesage.com

Posted: Fri Mar 03, 2006 4:50 pm
by nickman013
In that code you are redirecting users before they can see that link.

Try changing the page extension to PHP, that might not be it, but it worked for me before.

Not it

Posted: Fri Mar 03, 2006 4:54 pm
by vidya
The site has an .htaccess set so that all html pages are treated as PHP pages.

And yes, I want to redirect users instantly.
Doesn't matter what code is below the header function.

Eventually, it will be statistic gathering.

Thanks

...Vidya

Posted: Fri Mar 03, 2006 4:57 pm
by feyd
the query part of the call should probably be encoded

rawurlencode()

Posted: Fri Mar 03, 2006 4:58 pm
by nickman013
oh, i dont think your .htaccess works right.

when i tested the code in PHP it worked.

when I tested in HTML it didnt

Here's the atual reason it didn't work

Posted: Sat Mar 04, 2006 12:37 pm
by vidya
I found out why it wasn't working.

When you have:
http://www.somedomain.com/link.html?pg= ... ct=2026855

where the link.html routine is doing a GET on the pg variable, the GET[pg] variable
is actually only http://www.americanprogressaction.org/s ... =klLWJcP7H

There's also a GET variable that is 1331575
and a GET[ct] that is 2026855

You can't just redirect to GET[pg]
You have to reassemble all the GET variables (using foreach)
and then redirect.

Simple when you see it!

....Vidya

Posted: Sat Mar 04, 2006 12:40 pm
by feyd
using a urlencoded string wouldn't require any rigging like that.

Posted: Sat Mar 04, 2006 12:50 pm
by nickman013
It worked for me. (when it was a php file)