zoukankan      html  css  js  c++  java
  • http header前为什么不能有空格

    <?php
    session_start();
    ?>

    在这个代码前如果有一个空格。When you make this tiny change, you are given a particularly venomous error
    message:
    Warning: session_start() [function.session-start]: Cannot send session
    cookie - headers already sent by (output started at
    /opt/lampp/htdocs/sites/startingchapter/sessions.php:1) in
    /opt/lampp/htdocs/sites/startingchapter/sessions.php on line 3
    The reason it is so important to not have anything before session_start() is
    that the sessions framework makes use of the HTTP headers that form the mechanics
    of the Web page. These special headers are pre-pended to each Web page and as
    such, if you add any content before session_start(), the script will be trying to
    send out content (such as the white space), then the headers, and then the main
    content. This is not the way the Web works and, hence, PHP will shout at you in the
    form of the previous warning message.

    All About Headers
    Every Web page on the Internet has some information called headers that
    is invisible to most users. Headers store a number of pieces of information
    that browsers care about. Here are some example headers:

    GET / HTTP/1.
    Host: www.yourfavewebsite.org
    Connection: close
    Accept-Encoding: gzip
    Accept: text/xml,application/xml,application/xhtml+xml,
    text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: en-gb,en;q=0.5
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB;
    rv:1.8.0.3) Gecko/20060523 Ubuntu/dapper Firefox/1.5.0.3
    Referer: http://www.someotherwebsite.net/

    Beneath the headers lies the content. When you add content to the page,
    the headers are added automatically. As such, when data is added to the
    page, the headers are also sent and cannot be modified after they have
    been sent. 一旦发送内容是heaer也跟着发送就不能更改了。
    When you use sessions, the sessions system modifies some of these headers,
    and this is why you must add session_start() before any data is
    added to the page.

  • 相关阅读:
    架构师的成长之路初片~ntp时间同步
    架构师的成长之路初片~水晶头的颜色排序
    架构师的成长之路初片~Python-邮件(smtplib)、requests模块、API接口调用
    架构师成长之路之~调优思维
    架构师的成长之路初片~python~调整背景及滚轮+各种快捷键
    架构师成长之路之~Node.js安装篇
    微服务技术栈
    C#资源释放(托管资源、非托管资源)
    Beyond Compare 4 密匙
    MySql批量导入 .netcore命名空间完全相同问题
  • 原文地址:https://www.cnblogs.com/youxin/p/2646636.html
Copyright © 2011-2022 走看看