Re: Header - Redirect Command Not Working

From: Date: Tue, 10 Mar 2009 19:21:12 +0000
Subject: Re: Header - Redirect Command Not Working
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-289789@lists.php.net to get a copy of this message
On Tue, Mar 10, 2009 at 15:13, revDAVE <Cool@hosting4days.com> 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@parasane.net || danbrown@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

« previous php.general (#289789) next »