Bluehost.com Web Hosting $6.95

header(Location: $var) loops in IE

This is a discussion on header(Location: $var) loops in IE within the PHP Language forums, part of the PHP Programming Forums category; Hello everyone, I was wondering what could possibly cause Internet Explorer 6 to loop a page usging a header(Location:) ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-13-2006
P-Rage
 
Posts: n/a
Default header(Location: $var) loops in IE

Hello everyone,

I was wondering what could possibly cause Internet Explorer 6 to loop a
page usging a header(Location:) statement.

For example, a page called 'page1.php':

if((isset($_POST['var'])) && ($name='valid')){

// insert some data into MySQL.

$location = 'page2.php?name='.$name;
header(sprintf("Location: %s",$location));
exit();
}

FireFox redirects the user to page2.php as planned. But IE6 loops back
to page1.php (refreshes twice on most occasions). Any ideas? Thanks in
advance for any help and advice.

Reply With Quote
  #2 (permalink)  
Old 07-13-2006
Benjamin Esham
 
Posts: n/a
Default Re: header(Location: $var) loops in IE

P-Rage wrote:

> I was wondering what could possibly cause Internet Explorer 6 to loop a
> page usging a header(Location:) statement.
>
> For example, a page called 'page1.php':
>
> if((isset($_POST['var'])) && ($name='valid')){
>
> // insert some data into MySQL.
>
> $location = 'page2.php?name='.$name;
> header(sprintf("Location: %s",$location));
> exit();
> }
>
> FireFox redirects the user to page2.php as planned. But IE6 loops back to
> page1.php (refreshes twice on most occasions). Any ideas? Thanks in
> advance for any help and advice.


Technically, the location you pass should be an absolute URL; try replacing
your code with something more like

header('Location: http://www.example.com/page2.php?name=' . $name);

That may or may not make your page work; I'm not sure.

(By the way, the statement $name='valid' in your if statement probably
doesn't do what you want it to do: it assigns the value 'valid' to $name,
instead of checking to see whether the two are equivalent. If that's an
actual excerpt from your code, change it to $name == 'valid' in order to
avoid unexpected behavior.)

HTH,
--
Benjamin D. Esham
bdesham@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
"...English is about as pure as a cribhouse whore. We don't just
borrow words; on occasion, English has pursued other languages
down alleyways to beat them unconscious and rifle their pockets
for new vocabulary." — James Nicoll
Reply With Quote
  #3 (permalink)  
Old 07-13-2006
P-Rage
 
Posts: n/a
Default Re: header(Location: $var) loops in IE


Benjamin Esham wrote:
> P-Rage wrote:
>
> > I was wondering what could possibly cause Internet Explorer 6 to loop a
> > page usging a header(Location:) statement.
> >
> > For example, a page called 'page1.php':
> >
> > if((isset($_POST['var'])) && ($name='valid')){
> >
> > // insert some data into MySQL.
> >
> > $location = 'page2.php?name='.$name;
> > header(sprintf("Location: %s",$location));
> > exit();
> > }
> >
> > FireFox redirects the user to page2.php as planned. But IE6 loops back to
> > page1.php (refreshes twice on most occasions). Any ideas? Thanks in
> > advance for any help and advice.

>
> Technically, the location you pass should be an absolute URL; try replacing
> your code with something more like
>
> header('Location: http://www.example.com/page2.php?name=' . $name);
>
> That may or may not make your page work; I'm not sure.
>
> (By the way, the statement $name='valid' in your if statement probably
> doesn't do what you want it to do: it assigns the value 'valid' to $name,
> instead of checking to see whether the two are equivalent. If that's an
> actual excerpt from your code, change it to $name == 'valid' in order to
> avoid unexpected behavior.)
>
> HTH,
> --
> Benjamin D. Esham
> bdesham@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
> "...English is about as pure as a cribhouse whore. We don't just
> borrow words; on occasion, English has pursued other languages
> down alleyways to beat them unconscious and rifle their pockets
> for new vocabulary." - James Nicoll


Thanks for your reply! Yes that was a typo ($name == 'valid'). I am
still getting these loops occasionally after using an explicit
http-location header... any other ideas? Thanks again!

Reply With Quote
  #4 (permalink)  
Old 07-13-2006
Adam Plocher
 
Posts: n/a
Default Re: header(Location: $var) loops in IE

P-Rage, I'm not sure if this will help, but what if you put an exit();
after the header()? I've gotten in a habit of doing that due to some
weird issues I've found in the past (not sure if it was a buggy version
of PHP or IE).

Also, maybe try a couple variations in the header(). If you haven't
tried this already, try using the full URL (
"http://blah.com/page2.php?name={$name}" ) or maybe try prefixing it
with a ./ ( "./page2.php?name={$name}" ).

Hope that helps.


P-Rage wrote:
> Benjamin Esham wrote:
> > P-Rage wrote:
> >
> > > I was wondering what could possibly cause Internet Explorer 6 to loop a
> > > page usging a header(Location:) statement.
> > >
> > > For example, a page called 'page1.php':
> > >
> > > if((isset($_POST['var'])) && ($name='valid')){
> > >
> > > // insert some data into MySQL.
> > >
> > > $location = 'page2.php?name='.$name;
> > > header(sprintf("Location: %s",$location));
> > > exit();
> > > }
> > >
> > > FireFox redirects the user to page2.php as planned. But IE6 loops back to
> > > page1.php (refreshes twice on most occasions). Any ideas? Thanks in
> > > advance for any help and advice.

> >
> > Technically, the location you pass should be an absolute URL; try replacing
> > your code with something more like
> >
> > header('Location: http://www.example.com/page2.php?name=' . $name);
> >
> > That may or may not make your page work; I'm not sure.
> >
> > (By the way, the statement $name='valid' in your if statement probably
> > doesn't do what you want it to do: it assigns the value 'valid' to $name,
> > instead of checking to see whether the two are equivalent. If that's an
> > actual excerpt from your code, change it to $name == 'valid' in order to
> > avoid unexpected behavior.)
> >
> > HTH,
> > --
> > Benjamin D. Esham
> > bdesham@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
> > "...English is about as pure as a cribhouse whore. We don't just
> > borrow words; on occasion, English has pursued other languages
> > down alleyways to beat them unconscious and rifle their pockets
> > for new vocabulary." - James Nicoll

>
> Thanks for your reply! Yes that was a typo ($name == 'valid'). I am
> still getting these loops occasionally after using an explicit
> http-location header... any other ideas? Thanks again!


Reply With Quote
  #5 (permalink)  
Old 07-13-2006
Jerry Stuckle
 
Posts: n/a
Default Re: header(Location: $var) loops in IE

P-Rage wrote:
> Hello everyone,
>
> I was wondering what could possibly cause Internet Explorer 6 to loop a
> page usging a header(Location:) statement.
>
> For example, a page called 'page1.php':
>
> if((isset($_POST['var'])) && ($name='valid')){
>
> // insert some data into MySQL.
>
> $location = 'page2.php?name='.$name;
> header(sprintf("Location: %s",$location));
> exit();
> }
>
> FireFox redirects the user to page2.php as planned. But IE6 loops back
> to page1.php (refreshes twice on most occasions). Any ideas? Thanks in
> advance for any help and advice.
>


What does page2.php do? Is it possible it's doing some checking and
redirecting the user back to page1.php?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #6 (permalink)  
Old 07-13-2006
P-Rage
 
Posts: n/a
Default Re: header(Location: $var) loops in IE


Jerry Stuckle wrote:
> P-Rage wrote:
> > Hello everyone,
> >
> > I was wondering what could possibly cause Internet Explorer 6 to loop a
> > page usging a header(Location:) statement.
> >
> > For example, a page called 'page1.php':
> >
> > if((isset($_POST['var'])) && ($name='valid')){
> >
> > // insert some data into MySQL.
> >
> > $location = 'page2.php?name='.$name;
> > header(sprintf("Location: %s",$location));
> > exit();
> > }
> >
> > FireFox redirects the user to page2.php as planned. But IE6 loops back
> > to page1.php (refreshes twice on most occasions). Any ideas? Thanks in
> > advance for any help and advice.
> >

>
> What does page2.php do? Is it possible it's doing some checking and
> redirecting the user back to page1.php?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================


Adam,

I have `exit();` at the end, and that's working, since it doesn't allow
an echo statement after that. I will try the `./` approach, but I find
it odd that IE is the only browser affected by whatever is causing this
issue.

Jerry,

There's nothing in page2.php that brings anything back to page1.php. In
fact, I don't even reach page2.php (tested with a `echo "Page 2.";
exit();` line at the very top of page2.php). Perhaps the answer lies
with previous headers? The following was include()'ed at the top of the
page. It seems pretty standard based on the docs I have read.

Code:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Thanks for the replies you guys...

Reply With Quote
  #7 (permalink)  
Old 07-14-2006
Jerry Stuckle
 
Posts: n/a
Default Re: header(Location: $var) loops in IE

P-Rage wrote:
> Jerry Stuckle wrote:
>
>>P-Rage wrote:
>>
>>>Hello everyone,
>>>
>>>I was wondering what could possibly cause Internet Explorer 6 to loop a
>>>page usging a header(Location:) statement.
>>>
>>>For example, a page called 'page1.php':
>>>
>>>if((isset($_POST['var'])) && ($name='valid')){
>>>
>>> // insert some data into MySQL.
>>>
>>> $location = 'page2.php?name='.$name;
>>> header(sprintf("Location: %s",$location));
>>> exit();
>>>}
>>>
>>>FireFox redirects the user to page2.php as planned. But IE6 loops back
>>>to page1.php (refreshes twice on most occasions). Any ideas? Thanks in
>>>advance for any help and advice.
>>>

>>
>>What does page2.php do? Is it possible it's doing some checking and
>>redirecting the user back to page1.php?
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================

>
>
> Adam,
>
> I have `exit();` at the end, and that's working, since it doesn't allow
> an echo statement after that. I will try the `./` approach, but I find
> it odd that IE is the only browser affected by whatever is causing this
> issue.
>
> Jerry,
>
> There's nothing in page2.php that brings anything back to page1.php. In
> fact, I don't even reach page2.php (tested with a `echo "Page 2.";
> exit();` line at the very top of page2.php). Perhaps the answer lies
> with previous headers? The following was include()'ed at the top of the
> page. It seems pretty standard based on the docs I have read.
>
>
Code:
> header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
> header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
> header("Cache-Control: no-store, no-cache, must-revalidate");
> header("Cache-Control: post-check=0, pre-check=0", false);
> header("Pragma: no-cache");
>
>
> Thanks for the replies you guys...
>


Hmmm, that could be what's causing IE to not like it. When I'm going to
redirect I don't send *anything* before the Location: header.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:14 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0