By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

why "header" does not work in my code?

P: 5
hello ^^


i used header in my codes, and it was working fine in the local server. but when i upload it to the public server i keep get the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/movc/public_html/dbconnector.php:23) in /home/movc/public_html/loginaction.php on line 31


in dbconnector.php :
i connect to the server and i never used header there!

and in loginaction.php i used:
[code] include_once("dbconnector.php"); [/DODE]

and this is the part of my code that i used header in:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     //Check whether the query was successful or not
  3.     if($result) {
  4.         header('location: welcome_msg1.php');
  5. exit();}
  6.     else
  7.     header('location: erorr_msg1.php');
  8. exit(); 
  9.  

can you please tell me where i did wrong?
thanks so much ^^
May 11 '12 #1
Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
itís like the error messages says, 8 lines before you set the header, you have output, which causes the response body to begin and which renders any more headers invalid.
May 12 '12 #2

P: 5
thank you so much ^^ :*

but, what kind of error?
i review the code many times and couldn't find it!

if you can help me more and see the code:
Expand|Select|Wrap|Line Numbers
  1. //Create query
  2.  
  3.     $qry="SELECT * FROM user WHERE username='"$un"' AND pw='"$pw"';";
  4.     $result=mysql_query($qry);
  5.  
  6.     //Check whether the query was successful or not
  7.     if($result) {
  8.     if(mysql_num_rows($result) == 1) {
  9.             //Login Successful
  10.  
  11.             $member = mysql_fetch_assoc($result);
  12.             $_SESSION['uid'] = $member['u_id'];
  13.  
  14.             header("location: controlpanel.php");
  15.  
  16.             exit();
  17.         }else {
  18.             //Login failed
  19.             header("location: index.php");
  20.  
  21.             exit();
  22.         }
  23.     }else {
  24.         die("Query failed");
  25.     }
  26.  
  27.  
May 14 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
that kind of error:
Warning: Cannot modify header information - headers already sent by (output started at /home/movc/public_htm/dbconnector.php:23) in /home/movc/public_html/loginaction.php on line 31
May 14 '12 #4

P: 5
^^
i mean the error in the code!
what i should change in my code to make this error msg stop!!
May 14 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
remove the output before the header() call.
May 14 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.