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