• <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 - 标头已发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  • <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'>