Click to See Complete Forum and Search --> : start_session() problem


ceanth
06-26-2003, 05:10 AM
Hi all everytime i use the start_session(); statement i get this error:

Warning: Cannot send session cookie - headers already sent by (output started at /homes/cghe11/public_html/finalsite/php/validatelogin.php:13) in /homes/cghe11/public_html/finalsite/php/validatelogin.php on line 36

Warning: Cannot send session cache limiter - headers already sent (output started at /homes/cghe11/public_html/finalsite/php/validatelogin.php:13) in /homes/cghe11/public_html/finalsite/php/validatelogin.php on line 36


anyone know why this is happening?

Jick
06-26-2003, 05:30 AM
Just a suggestion, but it would probably help if you posted your code from the file your getting the error from so we can see what might be causing the problem. :p

ceanth
06-26-2003, 05:39 AM
ah i got it work but i might as well post the solution just in case anyone else gets this error.

I had

<?
session_start();

include 'db.php';

$result = mysql_query("SELECT * FROM staff ");
while ($r = mysql_fetch_array($result)) {
if ($r[1] == $uname) {
if ($r[2] == $pass) {

echo "we have a match";

}
}
else echo "error";
}

?>

and it gave me an error but then i put the session_start() at the top of the coding (as i had html coding b4 the <? ) and it worked.

pyro
06-26-2003, 07:41 AM
PHP sessions use HTTP headers (generally, you are using cookies) and thus must be set before any content is displayed on the page -- either echoed in PHP or written in with HTML.