Closed Thread Icon

Preserved Topic: header error: php sessions (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21137" title="Pages that link to Preserved Topic: header error: php sessions (Page 1 of 1)" rel="nofollow" >Preserved Topic: header error: php sessions <span class="small">(Page 1 of 1)</span>\

 
mwasisco
Obsessive-Compulsive (I) Inmate

From: chicago, IL usa
Insane since: Jan 2003

posted posted 03-05-2003 09:00

hola! any clue why i'm getting the header error at the following page?
http://www.wasisco.com/eastbankclub/authentication3/success.php

here's the code:

<?

session_start();

// check session variable

if(session_is_registered("valid_user"))

{
echo "You are logged in";
}

else
{
echo "You must be logged in to view this page <br>";
echo "<a href=login.html>Click here</a> to log in.";
}

?>

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-05-2003 09:24

you probably have a newline, or a whitespace before the first <?.
That way, something is already printed, and the headers can not be sent anymore.

so long,

Tyberius Prime

Kriek
Maniac (V) Inmate

From: Florida
Insane since: Jul 2001

posted posted 03-05-2003 15:31

Tyberius is correct, however sometimes it's not that simple =)

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

Output buffering (PHP 4.0) was originally designed to solve HTTP header errors.

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(). I should also mention that Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. 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.

__________________

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-05-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-05-2003 15:46

output buffering of course will prevent 'bigger' pages from being displayed before the php script has flushed the buffer.
This can be a draw back,
and it is also a strain on the server,
use with care.

« BackwardsOnwards »

Show Forum Drop Down Menu