php 警告:session_start() [function.session-start]:无法发送会话缓存限制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7373853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:34:18  来源:igfitidea点击:

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

phpsession

提问by Mehdi Hosseini

I have a problem with Session_start() here :

我在这里 Session_start() 有问题:

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.phpon line 2

警告:session_start() [function.session-start]:无法发送会话缓存限制器 - C:\xampp\htdocs\charts 中的标头已发送(输出开始于 C:\xampp\htdocs\pages\home.php:4)\home-chart.php2

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

在第 2 行的 home-chart.php 中,我编写了如下代码:

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['user_name']但是当我尝试清除这部分代码时:

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:2px;'>
                    <?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>

回答by Joe

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

如果您在<?php标签之前甚至有空行,那么您就无法设置标题。带有行号的文件开头应如下所示:

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

该消息显示“在第 2 行发送的标头”,因此您在 home.php 的第 4 行输出了一些内容(空格、空行等)

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.

如果这个文件是一个包含,你应该把你的session_start();放在 home.php 的顶部,然后你就不需要它在这个文件中了。

回答by Arnaud Le Blanc

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

这意味着你在调用 session_start() 之前打印了一些东西。

You must not print anything before session_start().

在 session_start() 之前你不能打印任何东西。

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

该错误消息表明您首先在 C:\xampp\htdocs\pages\home.php 中的第 4 行打印了一些内容。

回答by josef

write this code before headtag. like below:

head标记之前编写此代码。像下面这样:

<?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>

回答by xuri

  1. Open your php.ini file,
  2. Modifications session.auto_start = 0to session.auto_start = 1
  3. Restart apache service.
  1. 打开你的php.ini file
  2. 修改session.auto_start = 0session.auto_start = 1
  3. 重启apache服务。

回答by Ankit Adlakha

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

我也遇到了同样的问题,并通过在 php 页面顶部编写以下代码解决了同样的问题:

<?php
session_start();
?>

回答by hitesh kaushik

Use

session_cache_limiter(FALSE); 

before

session_start();

This will surely help you :)

这肯定会帮助你:)

回答by Timothy Bomer

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.

我知道这篇文章有点过时了,但我发现当文件的编码设置为包含 BOM 时我遇到了这个问题。当我将编码设置为 UTF-8(无 BOM)时,它解决了我的问题。

回答by Che Jug

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).

一些编辑器在将文件另存为 UTF-8 时,会在一开始就将额外的字符粘贴到文件中(格式不需要它,但他们还是这样做了)。然后在显示文件时拒绝向您显示这些字符。要查看您的编辑器是否属于其中之一,请尝试保存一个空文件并查看它占用了多少字节。如果它大于零(可能是三个),那么您将不得不告诉您的编辑器停止乱搞(以及您如何做到这一点取决于编辑器)。

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

如果将文件另存为 ANSI,则不会发生这种情况。

回答by Alex Onyia

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

尝试粘贴<?php ob_start(); ?>在页面的最顶部。它会像魔术一样工作。