Closed Thread Icon

Topic awaiting preservation: php "cannot add header information" (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12577" title="Pages that link to Topic awaiting preservation: php &amp;quot;cannot add header information&amp;quot; (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: php &quot;cannot add header information&quot; <span class="small">(Page 1 of 1)</span>\

 
mwasisco
Obsessive-Compulsive (I) Inmate

From: chicago, IL usa
Insane since: Jan 2003

posted posted 01-15-2003 11:17

hi. any clue why the following...

if($error == "0"){
header("location: http://www.wasisco.com/sucess.html");
}else{
header("location: http://www.wasisco.com/failed.html");
}

is returning...

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site226/fst/var/www/html/eastbankclub/authentication/validate.php:10) in /home/virtual/site226/fst/var/www/html/eastbankclub/authentication/validate.php on line 31


Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 01-15-2003 11:29

Take a look at the code referenced by the error messages. Somewhere, you've got a bug that's echoing output to the client before your location header goes off. Posting the code a few lines above and below the error references might help us understand what's going on.

mwasisco
Obsessive-Compulsive (I) Inmate

From: chicago, IL usa
Insane since: Jan 2003

posted posted 01-15-2003 12:02

Perfect Thunder: Thank you. It came to me while I was reading about the header function on php.net... my php script was unnecessarily inside <html> tags. I'm such a newbie.

For future reference, what if I needed to pass a url from a script inside an document? is it possible?


[This message has been edited by mwasisco (edited 01-15-2003).]

[This message has been edited by mwasisco (edited 01-15-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-15-2003 13:44

sorry, not 100% sure what you mean...

Any data passed via url.php?key=value will land in the
$HTTP_GET_VARS (or, in later PHP versions in $_GET).
That means you can access the value via
$HTTP_GET_VARS['key'] anywhere inside <?php ?> blocks.

I feel the need to ask you to read the php manual more carefully.
At least the first two dozen chapters (you can skip the various functions till you need them... but you should read the language introduction very thoroughly.). Also, I'm almost certain that your first problem is mentioned on the manual page that explaines header().

so long,
Tyberius Prime

[This message has been edited by Tyberius Prime (edited 01-15-2003).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-15-2003 14:10

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Kriek
Maniac (V) Inmate

From: Florida
Insane since: Jul 2001

posted posted 01-17-2003 04:10

Use output buffering with ob_start() and ob_end_flush().

code:
<?php ob_start(); 

// entire script, code, or page here

ob_end_flush(); ?>



Although ob_end_flush() isn't needed in MOST cases because it is called automatically at the end of script execution by PHP itself when output buffering is turned on either in the php.ini or by calling ob_start(). Output buffering (PHP 4.0) was originally designed to solve HTTP header errors.

__________________

Kriek says '[SYSTEMWIDE_MESSAGE] PHP Meetup'
What we do is never understood; only praised and blamed

[This message has been edited by Kriek (edited 03-04-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-17-2003 11:26

the drawback of outputbuffering should be mentioned as well: There is no output till your script reaches output_end_flush() (or output_flush()). That means, if you have a long running script, the user might see nothing of it.
But then, the server or the browser might buffer things as well, for example till the next newline, or the next </td> or so.
So the drawback is not actually that big, but if you got a long running script, make sure the user know's it's alive.

Kriek
Maniac (V) Inmate

From: Florida
Insane since: Jul 2001

posted posted 01-17-2003 14:41

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. So technically you do not have to wait the entire length of a script to output data. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order. I should also mention ob_get_contents(). Instead of sending output as-is, you can process it, manipulate it, and even cancel it as you see fit. Example: you could write the contents of an output buffer to a file before flushing it.

__________________

Kriek says '[SYSTEMWIDE_MESSAGE] PHP Meetup'
What we do is never understood; only praised and blamed

[This message has been edited by Kriek (edited 03-04-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu