Skip to main content
Inspiring
May 1, 2008
Question

Not redirecting with header() command

  • May 1, 2008
  • 6 replies
  • 377 views
I have this at the bottom of a code block -

if (!$error) {
mysql_select_db($database_connxxxx, $connxxxx);
$Result1 = mysql_query($updateSQL, $connxxxx) or die(mysql_error());

$updateGoTo = "items_Detail.php?ItemID=" . $itemID;
/*die($updateGoTo);*/
header("Location: " . $updateGoTo);
exit();
}

The code executes down to the header() command and leaves me with a blank
page (the exit() command). What's up with that?


--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


This topic has been closed for replies.

6 replies

Inspiring
May 2, 2008
Did you do something to my site? Now it's working!

<sigh>

8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"David Powers" <david@example.com> wrote in message
news:fvf0ho$t1q$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> But I know that the parser is not dieing since the page executes properly
>> all the way down to the line immediately above the redirect! The data is
>> added to the database, so I know I am in the loop, and if I insert a
>> die(); command immediately above the redirect, and have it print the
>> redirect value, that prints properly. So, I am puzzled.
>
> It means there's an error on the page that you're being redirected to.
>
> --
> David Powers, Adobe Community Expert
> Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
> Author, "PHP Solutions" (friends of ED)
> http://foundationphp.com/

Inspiring
May 2, 2008
Murray *ACE* wrote:
> But I know that the parser is not dieing since the page executes
> properly all the way down to the line immediately above the redirect!
> The data is added to the database, so I know I am in the loop, and if I
> insert a die(); command immediately above the redirect, and have it
> print the redirect value, that prints properly. So, I am puzzled.

It means there's an error on the page that you're being redirected to.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
May 2, 2008
> The reason is quite simple: If the script has a real error that
> causes the parser to die, you would never see any error message and just
> get a blank page, because the ini_set() calls will never be executed.

But I know that the parser is not dieing since the page executes properly
all the way down to the line immediately above the redirect! The data is
added to the database, so I know I am in the loop, and if I insert a die();
command immediately above the redirect, and have it print the redirect
value, that prints properly. So, I am puzzled.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:5bvl1457k25s9jvnql730skgc3hnrrph7p@4ax.com...
> .oO(Murray *ACE*)
>
>>The head of the page has this -
>>
>><?php ini_set('display_errors', 1); ?>
>
> And the error_reporting directive? It should be set to E_ALL|E_STRICT.
>
> On a development machine it's better to set these both directives in the
> php.ini. The reason is quite simple: If the script has a real error that
> causes the parser to die, you would never see any error message and just
> get a blank page, because the ini_set() calls will never be executed.
>
> Of course on the production server display_errors should be off and any
> errors written to a logfile instead.
>
>>> Do you send any output before the
>>> header() call, which would cause it to fail?
>>
>>I get NO error message.
>
> That's why I asked for the error_reporting. By default PHP doesn't show
> E_NOTICE errors, but sending any output before a header() call causes
> exactly that - a notice. With the default PHP setting you won't see it.
>
>>> Probably not the reason, but still a bug: The Location URI is required
>>> to be absolute.
>>
>>Really? I have always used it as relative and it's worked fine. Anyhow,
>>I
>>changed this one to absolute with the same results.
>
> It's required by the HTTP spec. With all the different user agents out
> there (not only browsers), you can't be sure that all are that forgiving
> with relative redirects. At least Lynx even shows a warning.
>
> Micha

Inspiring
May 2, 2008
.oO(Murray *ACE*)

>The head of the page has this -
>
><?php ini_set('display_errors', 1); ?>

And the error_reporting directive? It should be set to E_ALL|E_STRICT.

On a development machine it's better to set these both directives in the
php.ini. The reason is quite simple: If the script has a real error that
causes the parser to die, you would never see any error message and just
get a blank page, because the ini_set() calls will never be executed.

Of course on the production server display_errors should be off and any
errors written to a logfile instead.

>> Do you send any output before the
>> header() call, which would cause it to fail?
>
>I get NO error message.

That's why I asked for the error_reporting. By default PHP doesn't show
E_NOTICE errors, but sending any output before a header() call causes
exactly that - a notice. With the default PHP setting you won't see it.

>> Probably not the reason, but still a bug: The Location URI is required
>> to be absolute.
>
>Really? I have always used it as relative and it's worked fine. Anyhow, I
>changed this one to absolute with the same results.

It's required by the HTTP spec. With all the different user agents out
there (not only browsers), you can't be sure that all are that forgiving
with relative redirects. At least Lynx even shows a warning.

Micha
Inspiring
May 2, 2008
Micha:

The head of the page has this -

<?php ini_set('display_errors', 1); ?>

> Do you send any output before the
> header() call, which would cause it to fail?

I get NO error message.

> Probably not the reason, but still a bug: The Location URI is required
> to be absolute.

Really? I have always used it as relative and it's worked fine. Anyhow, I
changed this one to absolute with the same results.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:hmjk14ln60l7ecta9knr12g20rv31sevjj@4ax.com...
> .oO(Murray *ACE*)
>
>>I have this at the bottom of a code block -
>>
>>if (!$error) {
>> mysql_select_db($database_connxxxx, $connxxxx);
>> $Result1 = mysql_query($updateSQL, $connxxxx) or die(mysql_error());
>>
>> $updateGoTo = "items_Detail.php?ItemID=" . $itemID;
>> /*die($updateGoTo);*/
>> header("Location: " . $updateGoTo);
>> exit();
>>}
>>
>>The code executes down to the header() command and leaves me with a blank
>>page (the exit() command). What's up with that?
>
> Probably not the reason, but still a bug: The Location URI is required
> to be absolute.
>
> What about the error_reporting on your dev machine, is it set to
> E_ALL|E_STRICT in the php.ini? Do you send any output before the
> header() call, which would cause it to fail?
>
> Micha

Inspiring
May 1, 2008
.oO(Murray *ACE*)

>I have this at the bottom of a code block -
>
>if (!$error) {
> mysql_select_db($database_connxxxx, $connxxxx);
> $Result1 = mysql_query($updateSQL, $connxxxx) or die(mysql_error());
>
> $updateGoTo = "items_Detail.php?ItemID=" . $itemID;
> /*die($updateGoTo);*/
> header("Location: " . $updateGoTo);
> exit();
>}
>
>The code executes down to the header() command and leaves me with a blank
>page (the exit() command). What's up with that?

Probably not the reason, but still a bug: The Location URI is required
to be absolute.

What about the error_reporting on your dev machine, is it set to
E_ALL|E_STRICT in the php.ini? Do you send any output before the
header() call, which would cause it to fail?

Micha