473,668 Members | 2,491 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\pho enixhrsolutions \login.php:8) in C:\wamp\www\pho enixhrsolutions \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 1100
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
5464
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
3
3314
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 (after I set the appropriate $_SESSION value) but I get the following error: Warning: Cannot modify header information - headers already sent by (...)
5
1990
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: Cannot modify header information - headers already sent by (output started at /Users/chrobb/Sites/city-directory/controlBar.php:54) in /Users/chrobb/Sites/city-directory/controlBar.php on line 88 I've done a fair amount of searching and it looks...
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 without encountering this error. If I run the same code on two sites I will get the error on one site but not the other.
19
7919
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 limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
8
2387
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 page where is is to be validated then read into a MySQL table. Once that is done, the form is to send the user either back to the originating page, or to a logout page. I have several versions of this setup on my site that work well, so
2
1482
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) in my.class.php on line 1198 What is happening over here is that i when i am trying to download an attached file i am passing the additional header information which is conflicting with the header info which has already being sent before. ...
10
2360
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 'connectdb.php'; $id = $_GET;
0
2112
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 there is input otherwise it changes the template and lists the results on the other template page. That is why there is a $template variable. ==== $template = "template_carlist.html"; if ($_POST!='Open in Excel'){
3
2310
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
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8799
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8586
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4205
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2026
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.