1

After I uploaded my files this kind of error is occurred. But there is no any errors in my localhost. What kind of error is this? How to fix this?

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/lahiruca/public_html/events/includes/links.php:1) in /home/lahiruca/public_html/events/includes/header.php on line 1

(from the comments)

<?php session_start();?> 
<div class="header"> 
<div class="logo"></div> 
<div class="right_header"> 
<div class="top_right_header"> 
  <ul> <?php if(isset($_SESSION['userid'])){ ?> 
Nanne
  • 64,065
  • 16
  • 119
  • 163
Namal
  • 2,061
  • 3
  • 18
  • 26

1 Answers1

5

As the error says: You are trying to send headers (using the function session_start), but headers are allready sent.

Ways headers can be sent:

  • output is generated: this can be intended, like you allready did an echo,
  • or unintended (most of the times there can be some sort of whitespace in front of you <?php code. Or after a closing ?> in an included file
  • the header function
Nanne
  • 64,065
  • 16
  • 119
  • 163
  • this is my code. is there any prob? – Namal Dec 18 '11 at 15:28
  • Depending on the PHP-version and settings it could also be a [BOM](http://stackoverflow.com/questions/2558172/utf-8-bom-signature-in-php-files) before the ` – vstm Dec 18 '11 at 15:31
  • my guess is there is something before that line, The stuff that prints `` for instance. Sending `` to the browser is really what we are talking about: this is ouptut. You should not do any output before you call that session function. (please take care to add stuff like this to your question, you'll get better help. Don't add it as a comment) – Nanne Dec 18 '11 at 15:43
  • my problem is fixed. I have included link.php in index.php before include header.php. And there was a div tag before header include. So I remove session_start() from header.php and put in to the top of index.php. It works. thanks for helping me. – Namal Dec 18 '11 at 16:24