The code for PHPheader problems is as follows: Warning: Cannotmodifyheaderinformation-headersalreadysentby (outputstartedatD: AppServwwwadmin_check.php: 1) inD: AppServwwwadmin_check.php PHP header
The following code displays the following: Warning: Cannot modify header information-headers already sent by (output started at D: \ AppServ \ www \ admin_check.php: 1) in D: \ AppServ \ www \ admin_check.php on line 10
Require_once 'user _ service. class. php ';
$ Admin_id = $ _ POST ['admin _ id'];
$ Admin_password = $ _ POST ['admin _ password'];
$ UserService = new userservice ();
If ($ name = $ userService-> checkUser ($ admin_id, $ admin_password )){
Header ("Location: manage. php? Name = $ admin_id ");
Exit;
} Else {
Header ("Location: login. php? Error = 1 ");
Exit;
}
?> There is no problem at the front end of this code. it is caused by the execution of the header.
This is user_service.class.php
Require_once 'sqlhelper. class. php ';
Require_once 'user. class. php ';
Class userservice {
// Provides a method to obtain account information based on the user name
Public function getUserByName ($ name ){
$ SQL = "select * from user where name = '". $ name ."'";
$ SqlHelper = new sqlhelper ();
$ Arr = $ sqlHelper-> dql2 ($ SQL );
$ SqlHelper-> close_conn ();
Return $ arr ;//
}
// Provide a method to verify that the user is valid
Public function checkUser ($ name, $ password ){
$ SQL = "select password, name from user where name = '". $ name ."'";
// Create a sqlhelper object
$ SqlHelper = new sqlhelper ();
$ Res = $ sqlHelper-> dql ($ SQL );
If ($ row = mysql_fetch_assoc ($ res )){
// Compare the password
If ($ password = $ row ['password']) {
Return $ row ['name'];
}
}
Mysql_free_result ($ res );
$ SqlHelper-> close_conn ();
Return "";
}
Public function gengGPassword ($ name, $ newpassword ){
$ SQL = "update user set password = '". $ newpassword. "'Where name ='". $ name ."'";
$ SqlHelper = new sqlhelper ();
$ Res = $ sqlHelper-> dql ($ SQL );
// Mysql_free_result ($ res );
$ SqlHelper-> close_conn ();
}
}
?>
Sqlhelper. class. php code
// Tool
Class sqlhelper {
Public $ host = "localhost ";
Public $ user = "root ";
Public $ password = "123456 ";
Public $ db = "bishe ";
Public $ conn;
Public function sqlhelper (){
$ This-> conn = mysql_connect ("localhost", "root", "123456") or die ("123". mysql_errno ());
If (! $ This-> conn ){
Die ("connection failed". mysql_errno ());
}
Mysql_query ("set names utf8 ");
Mysql_select_db ($ this-> db, $ this-> conn );
}
Public function dql ($ SQL ){
$ Res = mysql_query ($ SQL, $ this-> conn) or die (mysql_errno ());
Return $ res;
}
Public function dql2 ($ SQL ){
$ Res = mysql_query ($ SQL, $ this-> conn) or die ("error! ". Mysql_errno ());
$ Arr = mysql_fetch_array ($ res, $ this-> conn );
Return $ arr;
/* Echo $ arr [0], $ arr ['1'];
$ Result = mysql_query ("SELECT * from user where name = 'xiaowang '");
While ($ row = mysql_fetch_array ($ result, MYSQL_NUM )){
Printf ("ID: % s Name: % s", $ row [0], $ row [1]);
}
Mysql_free_result ($ result );
Return $ row ;*/
}
// Public function dql2 ($ SQL ){
// $ Res = mysql_query ($ SQL, $ this-> conn) or die (mysql_errno ());
// Return $ res;
//}
// Delete?
Public function dml ($ SQL ){
$ B = mysql_query ($ SQL, $ this-> conn );
If (! $ B ){
Return 0; // failed
;
} Else {
If (mysql_affected_rows ($ this-> conn)> 0 ){
Return 1; // indicates that the execution is OK.
} Else {
Return 2; // indicates that no row is affected
}
}
}
Public function close_conn (){