tags:

views:

325

answers:

8

Recently I worked in a project there I wrote the following code in top of the page:

<?php 
session_start();
include_once('../module/connection.php');
$_SESSION['lang']=$_GET['ses'];
if(($_SESSION['lang']=='') || ($_SESSION['lang']=='english'))
{
  $l='japanese';
}
else if($_SESSION['lang']=='japanese')
{
  $l='english';
}

When I run that page it shows the following warning:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/sites/subdomains/www/html/ussl/juu/area/index.php:1) in /var/www/sites/subdomains/www/html/ussl/juu/area/index.php on line 1

How can I solve this?

+7  A: 

Is there any whitespace or other characters before your first "<?php" ? That would count as output. Also see this question. As is said in the error message, there's something in /var/www/sites/subdomains/www/html/ussl/juu/area/index.php on line 1. If your code snippet above is not from that file, go check it.

deceze
no white-space there. now what can i do?
Arif
Did you check for invisible/UTF-8 BOM characters, as described in the linked question?
deceze
I would delete the entire first line and rewrite it incase there are weird characters.
Chacha102
You may find deleting the first line doesn't help. I've had that problem before where an editor can't really see the invisible characters so doesn't delete them either. You might be better off copying and pasting what you want into a new file and deleting the old one, if you're not sure about your editor. Also try looking in Hex mode if your editor can do that.
cletus
+4  A: 

I would guess you've got some text before your <?php tag, which is essentially sending HTML to the client and thus headers are already sent. Anything there?

cletus
+2  A: 
Chacha102
Wow ... 4 people answered this really quickly
Chacha102
And always the usual suspects. Don't we have anything else to do? ;P
deceze
So I'm trying to hit my cap everyday.
Chacha102
no white-space there. now what can i do?
Arif
Try not going around to each person saying the same thing, because we can follow you through all the answers. There IS whitespace, you need to find it. Maybe try retyping the first few lines.
Chacha102
+2  A: 

You are outputting something before the use of session_start().

Make sure that there is nothing (by nothing I mean not even white-space) before <?php.


EDIT: As an alternative, you can add the following before session_start().

ob_start(); ob_clean();

I do not recommend using this workaround. Always find the cause of the problem and correct it instead of applying a workaround. Use the workaround only in last resort.

Andrew Moore
There is no white-space there. but the warning show. is there any more solution?
Arif
There is something causing an output before `session_start()`. Find out what it is.
Andrew Moore
We need a StackOverflow IRC Channel.
Chacha102
Actually, I recall my comment because then it would have said that the output was in a different file. Nope, it has to be on that file in line one, so it must be hidden whitespace or something.
Chacha102
+1  A: 

It sounds like maybe your webhost is sending the headers for something like adverts/banners?

That would be a really failure host.
Chacha102
Actually, this couldn't happen unless the host was inserting code into her page, which it isn't because it says that the error occurred on line 1 and was called on line one. If they were, it would say it was sent via their file.
Chacha102
A: 

check your logs for errors with session read/write permissions

Alex L
A: 
renilative
A: 

i had the same problem,
make a new php file, copy all lines from index.php but the first line it worked for me

Neo