Re: Header won't redirect
| From: | Chris Shiflett | Date: | Fri, 19 Sep 2003 15:36:45 +0000 |
| Subject: | Re: Header won't redirect | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163172@lists.php.net to get a copy of this message | ||
--- Jonathan Duncan <jonathan@nacnud.com> wrote:
> This is code that I have in my index that check whether or not SSL
> is being used when accessing certain pages and if not then it
> redirects to the same address but with SSL.
>
> if ($pagename=="login" || $pagename=="signup" ||
> $pagename=="checkout") {
> if (!$HTTPS) {
> //header("Location:
>
https://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?pagename=$pagename");
> exit;
> }
> }
>
> This used to work before I upgraded my PHP. Now when I click on a link
> that matches my SSL checker it just hangs:
>
> http://www.routerbitworld.com/index.php?pagename=checkout
>
> If I change the header to redirect to a location without any variable
> directive like this
>
> http://www.routerbitworld.com/index.php
>
> ...works fine. Why can't I send a variable this way?
You need to step back and do some debugging. I assume you just made a mistake
in your email, but you mentioned this not working:
http://www.routerbitworld.com/index.php?pagename=checkout
Now, if this is what your Location header is assigned to, you will send the
browser on an endless journey to find the resource it wants:
1. if ($pagename=="login" || $pagename=="signup" ||
$pagename=="checkout")
OK, yes it does (assuming register_globals is on). Let's go to the next step:
2. if (!$HTTPS)
Assuming this works as you expect, this conditional is still true, because you
used http in your URL. So, we continue:
3. Redirect to http://www.routerbitworld.com/index.php?pagename=checkout
Rinse. Repeat.
That would definitely be a problem.
Before I make any other guesses, try this (I always suggest this same thing):
For eac:
header('Location: http://example.org/');
Change this to:
echo 'Location: http://example.org';
Meaning, echo where you're trying to redirect rather than sending the header.
This way you can follow what's going on on the screen.
Hope that helps.
Chris
=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/