-1

Possible Duplicates:
PHP headers already sent
PHP session_start() error?

What does this error mean?

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/html/index.php:7) in /home/content/html/index.php on line 44

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/html/index.php:7) in /home/content/html/index.php on line 44

Here is my code:

session_start ();
if ($_SESSION['username']){
echo "User: " .$_SESSION['username']."<br>";
echo "<a href='logout.php'>Logout</a> <a href='account.php'>Account</a>";
}else{
echo "<a href='index.php'>Login</a> <a href='register.php'>Register</a>";

I have this code on my every page when I tested it on my localhost it works fine but when I uploaded the site on my remote server it displays this error. I can't understand why I can't start a session. I am using godaddy. Please help me.

Community
  • 1
  • 1
hamp
  • 85
  • 1
  • 7

2 Answers2

0

This is usually caused by leading whitespace. Your opening PHP tag is on line 4. It needs to be the first thing in index.php.

trutheality
  • 23,114
  • 6
  • 54
  • 68
0

If all worked on your localhost I guess you edited under Windows and published in an UNIX server, and your file encoding is UTF8 with BOM. If right you just have to remove the BOM, with Notepad++ eg.

MatTheCat
  • 18,071
  • 6
  • 54
  • 69
  • hey thanks for ur information yes i am useing windows but my hostion account is linux and i use dreamweaver. this is first website so i dont know much more about this can u provide me more information. in localhost all is fine but on real server some divs also not in their place.this is my code – hamp May 29 '11 at 03:45