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.

  • 相关阅读:
    Java Executors小结
    Java取得一个对象里所有get方法和set方法, 读取某个类下所有变量的名称
    js中的this
    style,ng-style, ng-attr-style的对比
    keil 赋值之后再声明变量提示错误error: #268: declaration may not appear after executable statement in block
    网络字节顺序为大端模式
    MDK警告 warning: #111-D: statement is unreachable
    #231-D: declaration is not visible outside of function
    linux修改文件所有者和文件所在组
    getpwuid()
  • 原文地址:https://www.cnblogs.com/youxin/p/2646636.html
Copyright © 2011-2022 走看看