Re: Header - Redirect Command Not Working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 10, 2009 at 15:13, revDAVE <Cool@xxxxxxxxxxxxxxxx> wrote:
> Newbie question...
>
> At the end of a php block I'm trying to use a redirect to go to another
> page.
>
> header('Location: show.php');
>
> It works on my test server w php 5.2.6 but not at the main server w v 5.12

    Did you already have some output sent to the browser?  That may be
causing header() not to be able to send the Location header to the
browser properly.

> Is there a way to get it to go to the other page (even with a different
> command/function) - or am I doing something wrong?

    Well, if the above is in fact the case (and yes, different
versions and installations have been known to respond differently),
then you can use a browser-based meta refresh, which will work for all
browsers anyway:

<?php
// .... your code....
header('Location: show.php');
echo '<meta http-equiv="refresh" content="0;show.php">';
flush();
exit(0);
?>

    This kills three birds with the same stone like so:

        1.) It tries to use the header() location redirect.
        2.) It falls back on browser-based redirection.
        3.) It forces a flush() of the data to the client, regardless
of minimum size limits.
        4.) It forces the script to exit with a non-error code of 0.

-- 
</Daniel P. Brown>
daniel.brown@xxxxxxxxxxxx || danbrown@xxxxxxx
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux