Php prompts Cannot send session cache when using session

Source: Internet
Author: User
Tags php session

When using php session today, the following prompt is displayed:

Warning: session_start () [function. session-start]: Cannot send session cache limiter-headers already sent (output started ..

Because there are other html code before the session_start (); statement

Solution:

Modify session. auto_start = 0 in php. ini to session. auto_start = 1.


Set variables

The code is as follows: Copy code

Session_register ("user ");
$ _ SESSION ["user"] = $ name;

Obtain

Session_start ();
Echo $ _ SESSION ["user"];

If the problem persists, check whether the encoding problem is correct.

1. Convert the error file to UTF-8 code without BOM format (I usually use Notepad ++ to convert)
2. Enable slowdown with ob_start? Write the output information in the partition to slow down? To avoid the headers output prior to session_start ().

The code is as follows: Copy code

<? Php
Ob_start ()
Echo "test"
Session_start ()
Ob_end_flush ()
?>

Some friends added: session. save_path = "C:/phpsession" [the path at the backend must be set by yourself and be sure to exist. In fact, this is incorrect. We have configured it when configuring php, do not modify the session if other programs have no problems. the save_path path is saved.

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.