Warning: session_start()

What is causes this warning?

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\xampp\htdocs\ est\ est.php:1) in D:\xampp\htdocs\ est\ est.php on line 2

There must be some HTML output before you use session_start(). You have to start session (or use that function) before any output to the browser’s header. So put that on top of your script file.


<?php // no output.. not even a single space before this PHP tag.
session_start();


my code:

<?php
session_start(); 
?>

my editor:notepad++
use of xampp
What is causes this warning?

Double check if there is a space before your first PHP tag.
Have you included that file in another file ?
Delete all the files in your xampp’s temp directory (C:\xampp\ mp)

Post the code of the page where you get this error. That will help to figure it out. There are ways to suppress that error, but not a good idea. 1st lets try to find the valid way.

thanks
rajug i work but not work
That is my code:

<?php
session_start(); 
?>

only that.

Did you try what I suggested in the last post (#4)?

yes, but not work

Have you got a Byte Order Mark (BOM) at the start? They’re not always visible if there are there but they can cause headers to be sent.

I wrote this way was not error:

<?php session_start(); ?>

what is different code above with code below?
why not have error code above and have error code below?

<?php 
session_start();  
?>

you can user ob_start() before session_start() to hide the error.

Make sure there are no blank spaces after <?php in your second example.

There is no difference in how those two will be interpreted.

In Notepad++ look at the bottom-right of the status bar. You will see something similar to one of these:

[list][]Dos\Windows ANSI
[
]Dos\Windows ANSI as UTF-8
[*]Dos\Windows UTF-8
[/list]

You can change the encoding of the page in the Format menu

If your text file is saved as “Dos\Windows UTF-8” your PHP code will have a problem, because there are some hidden characters at the very start of the code, called a byte-order mark. You can confirm this by using a hex editor to view the start of the text file.

The important thing to realise is that the BOM is output by the web server before it even gets to your PHP code, which screws up any attempts to use sessions.

Solution? Ensure that your php files are saved as ANSI code, whether that be actual ANSI code, or UTF-8 without the BOM mark (it’s in the Format menu).

you can also check there should not be blank space below ?> tag.

Blank spaces below there are okay, as long as the file is not being included by something else that runs before any output is allowed.

When you’re writing code that could be used like that, it’s better to have no ?> at the end of your code at all.

And this is one of the reasons I’m pushing for no tags mode on the dev list. After awhile answering this question gets to be annoying.

Good luck with your push to have the tags removed :wink: I don’t think it will happen. After all, if used properly there shouldn’t be any problems with them.

The push is to have the option to remove them and be able to specifiy the tag style of a file as it is being imported.

include(‘file.php’, PHP_TAGS_NONE );

would pull in a file without any tags while

include(‘file.php’);

would follow the php.ini setting for tags. The proposal also involves a more flexiable means to resolve multiple tag styles. So this is a problem it solves, but it also solves the problem of portability that php short tags have faced for awhile now.

By moving the tag style specification to runtime (insofar as you define the tag style as you include the file) you can, if you are designing a framework, ban tags from appearing in class files and related support files, limiting their presence to template files. It also eliminates mystery problems like those faced by the original poster.

It might be a whitespace issue. but usually notepad++ does not have those due to its friendliness to various coding languages compared to normal notepad for Mac or textEdit for Mac.

That is the only reason why I can see why having it on a new line is causing the error and all on one line is without error. I mean you are not interrupting a function or in this case the function session start…
this is a puzzling predicament and I would like to learn the solution

I wish you the best of luck!

PHP does read and interpret UTF-8 encoded files both with and without the BOM. If it does not interpret UTF-8 + BOM from notepad++ its due to the editor itself is creating the file wrong.

Though, note that PHP will not read and interpret UTF-16.