• <small id='rtFCZ'></small><noframes id='rtFCZ'>

    <i id='rtFCZ'><tr id='rtFCZ'><dt id='rtFCZ'><q id='rtFCZ'><span id='rtFCZ'><b id='rtFCZ'><form id='rtFCZ'><ins id='rtFCZ'></ins><ul id='rtFCZ'></ul><sub id='rtFCZ'></sub></form><legend id='rtFCZ'></legend><bdo id='rtFCZ'><pre id='rtFCZ'><center id='rtFCZ'></center></pre></bdo></b><th id='rtFCZ'></th></span></q></dt></tr></i><div id='rtFCZ'><tfoot id='rtFCZ'></tfoot><dl id='rtFCZ'><fieldset id='rtFCZ'></fieldset></dl></div>
    <tfoot id='rtFCZ'></tfoot>

      • <bdo id='rtFCZ'></bdo><ul id='rtFCZ'></ul>

      1. <legend id='rtFCZ'><style id='rtFCZ'><dir id='rtFCZ'><q id='rtFCZ'></q></dir></style></legend>

        无法发送会话 cookie - 标头已发送

        Cannot send session cookie - headers already sent(无法发送会话 cookie - 标头已发送)

            • <bdo id='keWZX'></bdo><ul id='keWZX'></ul>
            • <legend id='keWZX'><style id='keWZX'><dir id='keWZX'><q id='keWZX'></q></dir></style></legend>
                <tbody id='keWZX'></tbody>

                <tfoot id='keWZX'></tfoot>

              • <i id='keWZX'><tr id='keWZX'><dt id='keWZX'><q id='keWZX'><span id='keWZX'><b id='keWZX'><form id='keWZX'><ins id='keWZX'></ins><ul id='keWZX'></ul><sub id='keWZX'></sub></form><legend id='keWZX'></legend><bdo id='keWZX'><pre id='keWZX'><center id='keWZX'></center></pre></bdo></b><th id='keWZX'></th></span></q></dt></tr></i><div id='keWZX'><tfoot id='keWZX'></tfoot><dl id='keWZX'><fieldset id='keWZX'></fieldset></dl></div>

                <small id='keWZX'></small><noframes id='keWZX'>

                1. 本文介绍了无法发送会话 cookie - 标头已发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能重复:
                  已由 PHP 发送的标头

                  下面是我的 PHP 代码的一个简单示例(我希望如此)是不言自明的.我尝试做的是更新会话变量.但是脚本的输出如下:

                  Below is a simple example of my PHP code which (I hope so) is self explanatory. What I try to do is to update the session variable. But the output of the script is as follows:

                  警告:session_start()[function.session-start]:无法发送会话 cookie - 标头已发送由(输出开始于/Library/WebServer/Documents/facebook/test.php:8)在/Library/WebServer/Documents/facebook/test.php在第 11 行

                  Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Library/WebServer/Documents/facebook/test.php:8) in /Library/WebServer/Documents/facebook/test.php on line 11

                  当然,警告是由第 8 行和第 9 行中的 echo 语句引起的.是否有任何简单的解决方案来阻止此警告.

                  The warning is caused by the echo statements in line 8 and 9, of course. Is there any simple solution to stop this warning.

                  感谢任何指点,安德烈

                  <?php
                  session_start();
                  $_SESSION['percent'] = 0;
                  $iterations = 50;
                  
                  for ($i = 0; $i <= iterations; $i++) {
                    $percent = ($i / $iterations) * 100;
                    echo "Hello World!";
                    echo "<br />";
                    // update session variable
                    session_start();
                    $_SESSION['percent'] = number_format($percent, 0, '', '');
                    session_commit();
                  }
                  ?>
                  

                  对我来说唯一有效的解决方案(即更新会话变量)是:

                  The only solution that works (i.e. updates the session variable) for me is:

                  <?php
                  ob_start();
                  session_start();
                  $_SESSION['percent'] = 0;
                  $iterations = 50;
                  
                  for ($i = 0; $i <= 50; $i++) {
                    $percent = ($i / $iterations) * 100;
                    echo "Hello World!";
                    echo "<br />";
                    // update session variable
                    session_start();
                    $_SESSION['percent'] = number_format($percent, 0, '', '');
                    session_commit();
                  }
                  ob_flush();
                  ?>
                  

                  它很丑,虽然它首先缓冲输出......

                  It's ugly, while it buffers the output first...

                  推荐答案

                  输出开始后无法设置 cookie(或发送任何其他标头).您可以在第 1 行添加 ob_start() 来缓冲输出.

                  It's not possible to set cookies (or send any other headers) after output is started. You could add ob_start() at line 1 to buffer the output.

                  正确的解决方案是将逻辑与输出分开.检查例如http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=21

                  The right solution is to separate logic from the output. Check out e.g. http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=21

                  这篇关于无法发送会话 cookie - 标头已发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                  • <bdo id='CVhg5'></bdo><ul id='CVhg5'></ul>
                  • <i id='CVhg5'><tr id='CVhg5'><dt id='CVhg5'><q id='CVhg5'><span id='CVhg5'><b id='CVhg5'><form id='CVhg5'><ins id='CVhg5'></ins><ul id='CVhg5'></ul><sub id='CVhg5'></sub></form><legend id='CVhg5'></legend><bdo id='CVhg5'><pre id='CVhg5'><center id='CVhg5'></center></pre></bdo></b><th id='CVhg5'></th></span></q></dt></tr></i><div id='CVhg5'><tfoot id='CVhg5'></tfoot><dl id='CVhg5'><fieldset id='CVhg5'></fieldset></dl></div>

                  • <legend id='CVhg5'><style id='CVhg5'><dir id='CVhg5'><q id='CVhg5'></q></dir></style></legend>
                        <tbody id='CVhg5'></tbody>
                          <tfoot id='CVhg5'></tfoot>

                            <small id='CVhg5'></small><noframes id='CVhg5'>