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

  • 相关阅读:
    Ubuntu16.04下Django项目的部署
    Ubuntu16.04 下python2 | python3
    请求头请求体对应表
    Django项目开发-小技巧
    前端验证后端验证码问题
    Ugly Number
    移动0元素
    图片(画布上的图片)上传总结
    从矩阵中查找一个数
    搜索框(附带事件函数)
  • 原文地址:https://www.cnblogs.com/youxin/p/2646636.html
Copyright © 2020-2023  润新知