Warning: session_start () [function. Session-start]: cannot send session cookie-headers already sent

Source: Internet
Author: User
Tags php website

When configuring a PHP website, the following error occurs frequently on the header: Warning: session_start () [function. Session-start]: cannot send session cache limiter, which does not affect page opening.

 

Warning: session_start () [function. session-start]: cannot send session cache limiter-headers already sent (output started at D: \ orther object \ phptest \ Session. PHP: 1) In D: \ orther object \ phptest \ Session. PHP on line 2

1. if dreamwever is used and UTF-8 encoding is used, right-click a page and choose "Page property"> "title/encoding" to view a "including Unicode signature (BOM) (s) "check box, cancel it. This is because of the BOM contained in the UTF-8 encoded file, while PhP4 and 5 do not support Bom.

2. Modify session. auto_start = 0 in PHP. ini to session. auto_start = 1.

3. There is another way to add @ session_start () to session_start.

4. This information indicates that when the session is enabled, there is already content output. You can add ob_start () at the top ().

Ob is short for output buffering. Ob is correct and can speed up the webpage. However, adding ob functions blindly only increases the CPU burden. The basic role of OB.
1). Prevent the use of setcookie or header, session_start function errors after the browser outputs.

2 ). capture the output of some unrecoverable functions. For example, phpinfo will output a lot of HTML, but we cannot use a variable such as $ info = phpinfo (); to capture, at this time, OB will work.

3). process the output content, such as gzip compression, simple conversion, and replacement of some strings.

4) generating static files is actually capturing the output of the entire page and saving it as a file, which is often used in generating HTML or the whole page cache.

5. Add the following code to the PHP file header to block the warning error:
PHP code

<? PHP

// Put session_star () after session_star ()

Error_reporting (e_error );

Ini_set ("display_errors", "off ");

// Your PHP code

?>

Warning: session_start () [function. Session-start]: cannot send session cookie-headers already sent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.