开发者

Warning: session_start() [function.session-start]: Cannot send session cache limiter

I have a problem with Session_start() here :

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\pages\home.php:4) in C:\xampp\htdocs\charts\home-chart.php on line 2

and in home-chart.php in line 2 I wrote codes like this :

session_start();
.
.
.
echo ' username: '.$_SESSION['user_name'];

although with this warning i can get result of $_SESSION['user_name'] but when I try to clear this part of the code :

session_start();

I can't see any result in screen. so, what's your solution?

<?php
@session_start();
require_once '../class/chart.class.php';
$chart = new chart();
?>
<html>
    <head>
        <link href='../css/home-chart.css'  rel='stylesheet' type='text/css' />
    </head>
    <body>
        <div class='float_left' style="margin-bottom:20px;">
            <div class='float_left' style='line-height: 9.41px; font-size: x-small;'>0<br /></div>      <div class='float_left' style="background-image: url('../image/web/chart.png'); width: 367px; height: 226px; " >
                <!-- 1 --><div class='float_left float_left column' style='margin-left:2开发者_JAVA技巧px;'>
                    <?php echo $chart->mysql_fetch($chart->daycal(-3)); ?>
                </div>  
                <!-- 2 --><div class='float_left float_left column'>
                    <?php echo $chart->mysql_fetch($chart->daycal(-2)); ?>
                </div>  
                <!-- 3 --><div class='float_left column' >
                    <?php echo $chart->mysql_fetch($chart->daycal(-1)); ?>
                </div>  
                <!-- 4 --><div class='float_left column' >
                    <?php echo $chart->mysql_fetch($chart->daycal(0)); ?>
                </div>  
                <!-- 5 --><div class='float_left column' >
                    <?php echo $chart->mysql_fetch($chart->daycal(1)); ?>
                </div>  
                <!-- 6 --><div class='float_left column' >
                    <?php echo $chart->mysql_fetch($chart->daycal(2)); ?>
                </div>  
                <!-- 7 --><div class='float_left column' >
                    <?php echo $chart->mysql_fetch($chart->daycal(3)); ?>
                </div>  
            </div>


            <div class='float_single_full' ></div>
            <div class='float_left bottom_chart' style="margin-left:10px;"><?php echo $chart->dayofweek(-3); ?></div>
            <div class='float_left bottom_chart'><?php echo $chart->dayofweek(-2); ?></div>
            <div class='float_left bottom_chart'><?php echo $chart->dayofweek(-1); ?></div>
            <div class='float_left bottom_chart'  style='font-weight:bold'><?php echo $chart->dayofweek(0); ?></div>
            <div class='float_left bottom_chart'><?php echo $chart->dayofweek(1); ?></div>
            <div class='float_left bottom_chart'><?php echo $chart->dayofweek(2); ?></div>
            <div class='float_left bottom_chart'><?php echo $chart->dayofweek(3);
                    echo ' username: ' . $_SESSION['user_name'];
                    ?></div>
        </div>
    </body>
</html>


If you even have blank lines before the <?php tag, then you can't set headers. Your start of file, with line numbers, should look like this:

1. <?php
2. session_start();
3. header('Cache-control: private');

The message says "headers sent at line 2", so you're outputting something (a space, a blank line, whatever) on line 4 of home.php

If this file is an include, you should put your session_start(); at the top of home.php instead, and then you don't need it in this file.


It means that you printed something before calling session_start().

You must not print anything before session_start().

The error message suggests that you first printed something in C:\xampp\htdocs\pages\home.php at line 4.


write this code before head tag. like below:

<?php ob_start(); ?>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

session_start();
?>
</body>


  1. Open your php.ini file,
  2. Modifications session.auto_start = 0 to session.auto_start = 1
  3. Restart apache service.


If all the above answers didn't work out for you:

Some editors, when they save a file as UTF-8, stick extra characters into the file at the very beginning (the format doesn't require it, but they do it anyway). Then refuse to show you those characters when they display the file. To see if your editor is one of these, try saving an empty file and seeing how many bytes it takes up. If it's more then zero (probably three), then you'll have to tell your editor to stop messing around (and how you do that depends on the editor).

This is not happening if you save the file as ANSI.


Try pasting <?php ob_start(); ?> at the top most part of your page. It will work like magic.


I also faced the same problem and resolved the same by writting below code at top of the php page:

<?php
session_start();
?>


Use

session_cache_limiter(FALSE); 

before

session_start();

This will surely help you :)


I know this post is a little dated, but I found that I was getting this issue when the encoding of the files is set to include BOM. When I set the encoding to UTF-8 (WITHOUT BOM), it fixed my issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜