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.

  • 相关阅读:
    TCP/IP和HTTP的举例理解
    c#中栈和堆的理解
    c#设计模式之单例模式
    JSON.stringify实例应用—将对象转换成JSON类型进行AJAX异步传值
    JSON.stringify初识
    c# 过滤字符串中的重复字符
    C#中jQuery Ajax实例(二)
    C#中jQuery Ajax实例(一)
    jQuery动态对表格Table进行添加或删除行以及修改列值操作
    asp.net中控件的Attributes用法
  • 原文地址:https://www.cnblogs.com/youxin/p/2646636.html
Copyright © 2011-2022 走看看