PDA

View Full Version : Session - headers Error



d-machine
09-21-2008, 04:58 PM
Hi,

I don't know how to deal with this error:


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at XXX.php:15) in XXX.php on line 4


my php source code:


<?php

function username($num){
session_start();
$_SESSION['username']=$num;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my trial page</title>
</head>
<body>
<?php include ("sidebar.inc") ?>
bla bla
<?php
username(3);
?>
</body>
</html>

Nile
09-22-2008, 03:35 AM
http://us3.php.net/ob_start
I hope that helps you.

Moshambi
09-22-2008, 04:35 AM
I just do this for every file:



<?php session_start(); ?>

<?php

// Other code here

?>


If I put it on the top line like that by itself before anything else it seems to work perfectly. I am not sure if this is good or bad coding practice though, as I am still new to PHP. Hope this helped.

d-machine
09-22-2008, 04:01 PM
Thank you both very much !!

Now it is working great !