473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot modify header information

121 New Member
hello everybody

i am getting this type of error(shown below) after submitting the button in IE
browser, but the same code is working on Firefox smoothly,

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\phoenixhrsolutions\login.php:8) in C:\wamp\www\phoenixhrsolutions\login.php on line 126

i have database driven login authentication scripts. from the login page, if i enters username and password i am getting errors as shown above

any body knows please send me the solution

thank you
Nov 12 '07 #1
4 1094
Atli
5,058 Recognized Expert Expert
Hi.

The Warning you are getting there is produced by you PHP server-side code, so it is very unlikely that it would have anything to do with which browser you are using...

In any case. This warning is produced when you try to use the header() function after something has been printed. Once any content has been added to the response, the header information is locked an you can not modify it.

For example, this here will produce this warning, and you won't be redirected:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   echo "Hello";
  3.   header("Location: http://www.google.com");
  4. ?>
  5.  
While this will send you to Google.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   header("Location: http://www.google.com");
  3.   echo "Hello";
  4. ?>
  5.  
Check out the Output Control Functions for a simple way to control your output.
Nov 12 '07 #2
sbettadpur
121 New Member
Thanks a lot for ur reply, i am struggling very much from this issue,

but still i have doubt, and i.e not cleared, below i sending my script please
have a look, I will explain the script logic how the control is going.
once user enters username and password, then that values will compare with the database tables, if username is valid then it will create one session variable,
once session variable is set then that page is redirecting to index.php

index.php contains and header.php and footer.php

so, my question is where i have to put header information(i.e. redirection page).
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3.  
  4. include_once("functions.php");
  5. $cxn = connect_to_db("vars.php");
  6. ?>
  7. <html>
  8. <head>
  9. <script language='javascript'>
  10.   function load() {
  11.   var formObj = document.loginFrm.username;
  12.   formObj.focus();
  13. }
  14. </script>
  15. <title>Phoenix HR Solutions Login page</title>
  16. <link rel="stylesheet" href="style.css">
  17. </head>
  18.   <body background=back.gif onload='load();'>
  19. <?php
  20. #echo date("d/m/Y");
  21. function confirmUser($username,$password)
  22. {
  23.  
  24. #$query = "Select username, password from Users where username='$username' and password='$password'";
  25.  
  26.  $query = "Select Name, Confm_Passwd from Recruiter_Profile where Name='$username' and Confm_Passwd ='$password'";
  27.  
  28.  
  29.     #echo $query;
  30.  
  31.     $result = mysql_query($query) or die("Cannot execute the query");
  32.          #echo $result;        
  33.     $row = mysql_num_rows($result);
  34.  
  35.     #echo $row;
  36.     if(mysql_num_rows($result) != 1)
  37.  
  38.     return false; // 1 username exists
  39.  
  40.     else 
  41.  
  42.     return true;
  43.  
  44. }
  45. ?>
  46. <table bgcolor="#EDEDED" align="center" width=800 height=600 border=0 >
  47. <tr width=100% height=5%  cellpadding=0><td colspan=8 background="sidebar.gif" width=10% height=5%  class="ttitle"><div id="tttitle1"><img src="logo1.gif" ></img></div><div>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;PHOENIX HR SOLUTIONS&nbsp;&nbsp;&nbsp;&nbsp;</div> </td>
  48. </tr>
  49.  
  50. <tr><td>
  51. <table border='0'  height=20% cellspacing="8" cellpadding="8" align=center background=sidebar.gif class="MenuTable">
  52. <form method='post' name='loginFrm' action='login.php'>
  53. <br><br><br><br></br>
  54. <tr><td colspan=2 align=center class='field' style="font-family:verdana; font-size:12pt;">LOGIN</td></tr>
  55. <tr>
  56. <td class="Elementname"><b>User name</b></td><td><input type='text' size='20' name='username'></td></tr>
  57. <tr>
  58. <td class="Elementname"><b>Password</b></td><td><input type='password' size='21' name='pass'></td><br />
  59.  
  60.   <tr class=element><td colspan="2" align="center">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<input type='submit' name='submit' value='&nbsp;&nbsp;login&nbsp;&nbsp;'> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>
  61. </tr>
  62. </form>
  63. </td>
  64. </tr>
  65. <?php
  66. $username = $_POST['username'];
  67. $password = $_POST['pass'];
  68. $submit = $_POST['submit'];
  69.  
  70. #echo ($username);
  71. $crypt_pwd=md5($password);
  72. #echo ($crypt_pwd);
  73.  
  74. if(!empty($submit)){
  75.  
  76. if (!empty($username) && !empty($password)) {
  77.  
  78. #$cxn = mysql_connect("localhost","root","mysql");
  79.  
  80. #$db = mysql_select_db("phoenixhrdb",$cxn);
  81.  
  82. $auth = confirmUser($username,$crypt_pwd);
  83.  
  84. #echo "\n$auth";
  85.  
  86. if ($auth == "true") {
  87.  
  88.     $_SESSION['valid_user'] = $username;
  89. #    Write query ( select MAX(login_time) from logintimestamp where username='$username';
  90. #write the result into $lastlogin
  91. #        insert into logintimestamp values ($username, now(), NULL);
  92. #        :wq
  93.  
  94.       $time_query = "select MAX(logintime) from Logintimestamp where Username='$username'";
  95.     #echo $time_query;
  96.       $time_result = mysql_query($time_query,$cxn);
  97.       $time_row = mysql_fetch_array($time_result);
  98.       $lastlogin = $time_row['MAX(logintime)'];
  99.     #echo $lastlogin;
  100.       $_SESSION['login'] = $lastlogin;
  101.  
  102.     $insert_query = "INSERT INTO Logintimestamp values ('$username',now(),'NULL')";
  103.     # echo $insert_query;
  104.    $insert_result  =  mysql_query($insert_query,$cxn);
  105.  
  106. #            }
  107. if(true){
  108. $adminquery ="select Name from Recruiter_Profile where Team_Selection='Superuser' or Team_Selection='Management' or Team_selection='Manager'";
  109. $adminresult = mysql_query($adminquery) or die("Could not connect to database".mysql_error($cxn));
  110. #echo $adminresult;
  111.  
  112. while($adminrow = mysql_fetch_array($adminresult)){
  113. #echo $adminrow;
  114. $adminteam[]=$adminrow['Name'];
  115. }
  116. foreach($adminteam as $admin){
  117. #    echo "<br>$admin";
  118. #echo $username;
  119.        if($admin==$username){
  120. #    echo $admin;
  121.        header("Location:index.php");
  122.         exit;
  123. }
  124. else  if($admin !=$username){
  125. header("Location:indexcontinue.php");
  126.     exit;
  127. }
  128.     }}
  129. }
  130. else {
  131.  
  132.     echo ("<tr><td colspan='2'><b align='center'>Username or Password doesn't exist</b></td></tr>");
  133.     }
  134.  
  135. }
  136.  
  137.  
  138. else {
  139.  
  140.  
  141.     echo ("<tr><td colspan='2'><b>Please Enter user name and Password</b></td></tr>");
  142. }
  143.  
  144. }
  145. ?>      
  146. </table>
  147. </td></tr>
  148. <tr height=15><td  align=center background="sidebar.gif" colspan=8 cellpadding=0 cellspacing=0 class=footertxt>copyright2007 @ phoenixhrsolutions</td></tr>
  149. </table>
  150.            </body>
  151. </html>
  152.  
Nov 13 '07 #3
Atli
5,058 Recognized Expert Expert
The header() function must be called before anything is added to response. So calling the function where you do will never work. Unless you use the Output Control Functions.

A simpler example, in this case, would be to use Javascript to redirect the browser.
There is of course always a risk using Javascript, as the client's browser can be set to ignore Javascript.
You could try something like this, instead of your header call:
Expand|Select|Wrap|Line Numbers
  1. echo "<script type=\"text/javascript\">location.href='http://www.google.com';</script>";
  2.  
I would recommend, however, that you try to design all code, that requires the use of the header function, so that any calls the function are done before you print anything.
Nov 13 '07 #4
sbettadpur
121 New Member
Thank you very much Mr.Atli

my problem has solved, in any php script logic should come first then the display part has to come
means in my script i am printing forms before callling header function i interchange as u said.

thank you
Nov 14 '07 #5

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

Similar topics

8
5452
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
3309
by: Greg Scharlemann | last post by:
Does the redirect statement: header(Location:"http://www.newpage.com"); need to come before certain statements? I've setup a login page and try to redirect a user once they have logged in...
5
1984
by: Chris Robb | last post by:
I'm having some really odd behavior with a PHP script. I have it populating an HTML select form with a for loop. When I try the years 2006 to 1900. I get the following error: PHP Warning: ...
5
625
by: J Huntley Palmer | last post by:
I am getting this error: Cannot modify header information - headers already sent by when I issue a header ("Location: http://www.foobar.com"); How can I redirect the user to such a site...
19
7902
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
8
2385
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP...
2
1475
by: pks83 | last post by:
Hello I am also facing this problem when i amtrying to send additional header information. Warning: Cannot modify header information - headers already sent by (output started at header.php:96)...
10
2344
by: jessica87 | last post by:
hi there, i m using this coding to retrieve the file from database so that my user can download the file... <?php if (!isset($_GET)) die('Invalid Parameter'); include...
0
2097
by: JRough | last post by:
I have the following code at the end of a page that lists some query results. It starts in a form that asks the user for input, one of two template pages. One template is a form for user input if...
3
2289
by: pinko1204 | last post by:
My Update function cannot successful update to sql table even don't have any error. Please help to check .....thx PHP1 <?php require_once 'header.php'; ?> <style type="text/css"> <!--
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.