NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP REDIRECT

PaulCheung paulcheung at tiscali.co.uk
Wed Sep 5 09:26:25 EDT 2007


Thanks Hans and everybody else for the help, it is truely appreciated.

That certainly sorted that problem out and really fast too, I got away with 
just adding the line.

Paul
----- Original Message ----- 
From: "Hans Zaunere" <lists at zaunere.com>
To: "'NYPHP Talk'" <talk at lists.nyphp.org>
Sent: Wednesday, September 05, 2007 1:41 PM
Subject: RE: [nycphp-talk] PHP REDIRECT


>
>
> PaulCheung wrote on Wednesday, September 05, 2007 8:36 AM:
>> Thanks David, Dan and bz
>>
>> the missing quote was just a copying error. Using the
>> header('location: http://localhost/mainmenu.php');
>>
>> this is the value of $number_of_records  = 0
>> Warning: Cannot modify header information - headers already sent by
>> (output started at C:\xampp\htdocs\etestform.php:4) in
>> C:\xampp\htdocs\etestform.php on line 59
>>
>> This is the error message the 4 at the end of
>> C:\xampp\htdocs\etestform.php:4 - points to script line 4. which is
>>  <script language="JavaScript" type="text/javascript">
>>
>> Line 59 is
>> 57      if ($b == 0)
>> 58        {echo 'this is the value of $number_of_records  = ' .
>> $number_of_records;
>> 59        header('location: http://localhost/mainmenu.php');}
>> 60        else
>>
>> Using PseudoCode - Is there anything in PHP that will simply just
>> sayes the following
>>
>> If  $number_of_records == 0
>>     goto http://www.localhost/mainmenu.php ??
>
> There is, and you're trying to do it.  But the error you're getting 
> explains
> what the problem.  You can't send content to the browser before you send 
> the
> headers (which cause the redirect).
>
> At the very first line of your script, try adding:
>
> ob_start();
>
> The error message is not about the Javascript.  It's saying that you can't
> send headers after you've already sent page content.  ob_start() adds 
> output
> buffering, so you might be able to get away with just adding the above 
> line.
> But you should read the comments in the php.net/header document page to
> understand why it's working/not working.
>
> H
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 



More information about the talk mailing list