[FX.php List] PHP question...

Gareth Evans gareth.evans at schawk.com
Wed Apr 29 09:17:55 MDT 2009


You can put a header() anywhere you want as long as nothing has been output
to the browser. This example code works fine for me:

http://pastebin.com/m5afe64dc

-- 
GARETH EVANS


> From: Bob Patin <bob at patin.com>
> Reply-To: "FX.php Discussion List" <fx.php_list at mail.iviking.org>
> Date: Wed, 29 Apr 2009 10:06:48 -0500
> To: "FX.php Discussion List" <fx.php_list at mail.iviking.org>
> Subject: Re: [FX.php List] PHP question...
> 
> Gareth,
> 
> Thanks for the suggestion, but that doesn't fix the problem that a
> HEADER() won't work in the BODY of a page... tried it, nada...
> 
> I guess I just can't make it work. It seems like there *ought* to be a
> way to redirect from within the body of a page, but after searching
> the PHP docs, I can't find anything.
> 
> If anyone has a flash of inspiration, please let me know; thanks,
> 
> Bob Patin
> 
> 
> 
> 
> Longterm Solutions
> bob at longtermsolutions.com
> 615-333-6858
> http://www.longtermsolutions.com
> iChat: bobpatin
> AIM: longterm1954
> FileMaker 9 Certified Developer
> Member of FileMaker Business Alliance and FileMaker TechNet
> --------------------------
> FileMaker hosting and consulting for all versions of FileMaker
> PHP € Full email services € Free DNS hosting € Colocation € Consulting
> 
> On Apr 29, 2009, at 9:57 AM, Gareth Evans wrote:
> 
>> Maybe you can use output buffering to only send the page if $counter
>>> = 1.
>> 
>> ob_start();
>> ... 75% of page ...
>> $content = ob_get_contents();
>> ob_end_clean();
>> 
>> if ($counter < 1) {
>>   header("Location: review.php");
>> } else {
>>   echo $content;
>> }
>> 
>> 
>> -- 
>> GARETH EVANS
>> 
>> 
>>> From: Bob Patin <bob at patin.com>
>>> Reply-To: "FX.php Discussion List" <fx.php_list at mail.iviking.org>
>>> Date: Wed, 29 Apr 2009 09:47:07 -0500
>>> To: "FX.php Discussion List" <fx.php_list at mail.iviking.org>
>>> Subject: [FX.php List] PHP question...
>>> 
>>> I have a page that loads, and in the body of the code, there's a loop
>>> that occurs that tries to load in database records if any exist.
>>> Because of the way the site works, I have to run this loop in the
>>> body
>>> of the page and not at the top, so 75% of the page has already been
>>> loaded at this point.
>>> 
>>> What I'd *like* to do is go to the next page if no records are
>>> loaded;
>>> I have a variable that's easy to test, but I can't seem to get what I
>>> want.
>>> 
>>> I tried saying this:
>>> 
>>> if ($counter<1){
>>> header("Location: review.php");
>>> }
>>> 
>>> but for some reason, it doesn't actually send the user to the next
>>> page. I can test and confirm that the IF statement does validate and
>>> the code within IS run, but why doesn't it send the user to the next
>>> page? Is it because a lot of the HTML has already loaded?
>>> 
>>> If I use an INCLUDE() or REQUIRE(), the top part of this page will
>>> show on the subsequent page, which is of course not what I want.
>>> 
>>> Is there another way to redirect after the BODY of a page has already
>>> started loading?
>>> 
>>> Thanks,
>>> 
>>> Bob Patin
>>> 
>>> Longterm Solutions
>>> bob at longtermsolutions.com
>>> 615-333-6858
>>> http://www.longtermsolutions.com
>>> iChat: bobpatin
>>> AIM: longterm1954
>>> FileMaker 9 Certified Developer
>>> Member of FileMaker Business Alliance and FileMaker TechNet
>>> --------------------------
>>> FileMaker hosting and consulting for all versions of FileMaker
>>> PHP € Full email services € Free DNS hosting € Colocation €
>>> Consulting
>>> 
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>> 
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



More information about the FX.php_List mailing list