Questions about PHP + mysql login and sesiion

Source: Internet
Author: User
The home page of the PHP + mysql logon and sesiion problems reports an error. the error is: Warning: & nbsp; session_start () & nbsp; [function. session-start]: & nbsp; Cannot & nbsp; send & nbsp; session & nbsp; cookie & nbsp;-& nbsp; headers & nbsp; already & nbs PHP + mysql login and sesiion problems
An error is reported on the home page. the error is: Warning: session_start () [function. session-start]: Cannot send session cookie-headers already sent by (output started at F: \ Apache HTTP Server \ AppServ \ www \ ClassWeb. php: 8) in F: \ Apache HTTP Server \ AppServ \ www \ ClassWeb. php on line 7
Warning: session_start () [function. session-start]: Cannot send session cache limiter-headers already sent (output started at F: \ Apache HTTP Server \ AppServ \ www \ ClassWeb. php: 8) in F: \ Apache HTTP Server \ AppServ \ www \ ClassWeb. php on line 7


/********** Main Page code classweb. php **************/
Essence course network




Essence course network





}
?>




*****************/
Session_start ();
$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['password'];
@ $ Db = mysql_connect ('localhost', 'root', 'root'); // connect to the database
If (! $ Db ){
Die ('could not connect: '. mysql_error ());
}
// Echo 'connection successful! ';
Mysql_select_db ('wwj'); // select the database file wwj
// Execute the SQL statement
Mysql_query ("set names utf8"); // The database is utf8, and "-" is not found !!
$ SQL = "select * from pre_common_member where username = $ username ";
$ Result = mysql_query ($ SQL );
If ($ row = mysql_fetch_assoc ($ result )){
If ($ row ['password'] = md5 ($ password )){
$ Name = $ row ['username'];
Echo "script" alert ('login successful! ') Script ";
Session_register ('$ name ');
Header ('Location: ClassWeb. php'); exit ();
}
}
Echo "script alert ('user name or password is incorrect! ') Script ";
Header ('Location: ClassWeb. php'); exit ();
Mysql_free_result ($ result );
?>

There are a lot of code above. I know that it seems annoying, but I really don't know how to do it. I hope you can help me to find out why. Thank you !!
By the way, let me see if the code on the redirected login page is correct. thank you! Thank you !!
------ Solution ----------------------
Set Put it at the beginning of the file

No output is available before session_start ().
------ Solution ----------------------
Session_start (); no partitions can be output before. Put session_start (): put it at the beginning of the file to solve this problem.

------ Solution ----------------------
You can use the editor to save the BOM header as UTF-8 without bom format.
------ Solution ----------------------
Change file encoding to UTF-8 without bom header

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.