Forum Moderators: coopster

Message Too Old, No Replies

header redirect with GET variables

         

microaide

7:10 pm on May 8, 2007 (gmt 0)

10+ Year Member



I have PHP 5.2.2 installed on my WinXP machine. I am using the web server built into Proxy Plus, with PHP enabled using php-cgi.exe. It seem to be working fine, but I have a problem trying to redirect to a new page using the header() function.

When I do:
header('Location: mypage.php?var=fred');

The browser (Firefox 2.0.0.3) get redirected and shows the following in the location bar:
[localhost...]

Notice that the "=" gets changed to ":%20"

Of course this is not working. I have tried everything I can think of, including using %3d instead of =. Nothing seems to work. Any ideas? Could this be a problem with PHP, or a problem with the web server in Proxy Plus, or something else? I have NOT tried this on any other web server.

mcibor

8:48 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just performed a quick check and the following code works fine by me.
Could you try it?

header.php:

<?php
if(isset($_GET['test'])) echo "GET: {$_GET['test']}";
else header('Location: header.php?test=text');
?>

I use Mozilla, so the same what Firefox is based on. If it works for you, then the problem is sth else.

As I recall %20 means a blank space, so maybe here lies the problem?
Hope this sets you on the right track

Regards
Michal

[edited by: mcibor at 9:10 pm (utc) on May 8, 2007]

adb64

8:52 pm on May 8, 2007 (gmt 0)

10+ Year Member



Hi microaide

Welcome to WebmasterWorld

With the header you should include a full URL:


[url=http://www.php.net/manual/en/function.header.php]header[/url]('Location: http://www.example.com/mypage.php?var=fred');

Maybe that works, haven't tried.

Regards,
Arjan

jd01

8:56 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From the documentation:

Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

http:// is required for FireFox and other HTTP 1.1 complaint browsers.

Justin