vinsux Posted July 31, 2012 Share Posted July 31, 2012 when i log in i saw this error... please help Warning: Cannot modify header information - headers already sent by (output started at /home/ocmpq/public_html/index.php:3) in /home/ocmpq/public_html/index.php on line 94 Warning: Cannot modify header information - headers already sent by (output started at /home/ocmpq/public_html/index.php:3) in /home/ocmpq/public_html/index.php on line 95 Warning: Cannot modify header information - headers already sent by (output started at /home/ocmpq/public_html/index.php:3) in /home/ocmpq/public_html/index.php on line 99 here's my code <!DOCTYPE html> <html lang="en"> <?php include('include/header.php'); ?> <body> <?php include('include/container.php'); ?> <div id="main"> <section id="content"> <div id="left"> <h3>Navigation</h3> <div style="border: 1px solid #000000; margin-top: 20px; margin-left: 10px; margin-right: 10px; margin-bottom: 20px; background-color: #F5F5FF; "> <?php mysql_connect("localhost","mycpaneluser","mycpanelpass") or die(mysql_error()); mysql_select_db("ocmpq_login") or die(mysql_error()); $errors=""; $message=""; if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM students WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("index.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field...<a href=index.php>Back</a>'); } if (empty($errors)){ //continue //Check for valid type $allowed_types = array('students','faculty'); if (!in_array($_POST['type'],$allowed_types)){ $errors .= "Please select a valid account type."; }else{ $typecheck = $_POST['type']; } if (empty($errors)){ //continue if (get_magic_quotes_gpc()){ function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } } } $check = mysql_query("SELECT * FROM $typecheck WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.<a href=index.php>Back</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.<a href=index.php>Back'); } else { { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 9600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); } switch($typecheck) { case "students" : header("location:student.php"); break; default: header("location:faculty.php"); } } } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <br> <table border="0"> <br> <tr><th colspan=2><center><h5><b><u>login your account</b></u></h5></center> </th></tr> <tr><th><br>usn / id:</th><th> <br><input type="text" name="username" maxlength="20"> </th></tr> <tr><th><br>password:</th><th> <br><input type="password" name="pass" maxlength="20" > </th></tr> <tr> <th><br>login as:</th> <th colspan="3"> <br><select name= "type"> <?php $atype = array( "students" => "Student", "faculty" => "Teacher" ); foreach($atype as $tkey => $tvalue){ $selected_type = (isset($_POST['type']) && $_POST['type']==$tkey ? 'selected="selected"' : ''); echo "<option value=\"$tkey\" $selected_type>$tvalue</option>\r"; } ?> </select> </th> </tr> <tr><th colspan="2" align="center"> <br> <br> <input type="submit" name="submit" value="Login" style="width: 100px; height: 25px"> <br> <br> <br> <br> </th></tr> </table> </form> <?php } ?> </div> </div> <div id="right"> <h3>Online Course Materials</h3> <div style="border: 1px solid #000000; width :580px; margin-top: 20px; margin-left: 25px; margin-right: 20px; margin-bottom: 20px; padding:20px 20px 20px 20px ; background-color: #F5F5FF;"> <?php echo "<br />"; echo "<br />"; echo "<br />"; echo "  <b><i>AMA Online Course Materials Registration Procedure</i></b>"; echo "<br />"; echo "<br />"; echo "     - Only the faculty members can register a student"; echo "<br />"; echo "<br />"; echo "     - The registration process will require the students <br />       to present their IDs or CORs that will prevent forgeries <br />       in the information they will provide and to confirm which <br />       subjects is the student enrolled.<br> <br /><br /> "; echo " <p align='justify' style='margin-left:2em; margin-right:2em'> The project Online Course Material will be a web-based program that can access by the facultyand students of AMA Para?aque. The students must have a registered account so that they can access the website and the registration of the accounts of the students must be registered by their teachers to avoid outsiders to register to the website. </p> <br /> <p align='justify' style='margin-left:2em; margin-right:2em'> The full purpose of this project is intended to help the students and faculty to gather information from their subjects easily. And for the students who has to leave school for a while due to reasonable reasons like death of relatives, with the website they cannot skip some of the lessons in school. </p>"; ?> </div> </div> </div> <?php include('include/footer.php'); ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/ Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2012 Share Posted July 31, 2012 There's a sticky topic regarding this particular error. You must have overlooked it: HEADER ERRORS - READ HERE BEFORE POSTING THEM Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365729 Share on other sites More sharing options...
vinsux Posted July 31, 2012 Author Share Posted July 31, 2012 it's working in my localhost.. but when my site is up.. it has an header error... all my pages has this error... omg,.. i wannnaaaaa................................ Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365731 Share on other sites More sharing options...
KevinM1 Posted July 31, 2012 Share Posted July 31, 2012 You can't use header if you've already sent output through the browser. Just another example showing that jumping back and forth between HTML and PHP is a bad idea. Do all of your data handling/processing first, determine if you need to redirect, and, if so, do it right then and there. If not, only once everything has been stored in variables and ready to be displayed on the screen, should you start writing HTML. Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365734 Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2012 Share Posted July 31, 2012 Most likely, you have error reporting off on your local machine, and it only appears to work. While developing, error reporting should always be set to the highest level, and set to display all errors. Make sure you have error reporting set up properly on your local machine by configuring the following directives in your php.ini file: error_reporting = -1 display_errors = On Then restart Apache, and see if you get the same errors displayed. If you don't know where your php.ini file is, create a new script containing only this code and run it. You'll see the path to the file in the first section, under the "loaded configuration file" entry. Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365735 Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2012 Share Posted July 31, 2012 I've changed your thread title to reflect the problem more accurately. Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365737 Share on other sites More sharing options...
floridaflatlander Posted July 31, 2012 Share Posted July 31, 2012 <!DOCTYPE html> <html lang="en"> <?php include('include/header.php'); ?> I'm assuming you have doctype info in header.php Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365742 Share on other sites More sharing options...
vinsux Posted July 31, 2012 Author Share Posted July 31, 2012 Most likely, you have error reporting off on your local machine, and it only appears to work. While developing, error reporting should always be set to the highest level, and set to display all errors. Make sure you have error reporting set up properly on your local machine by configuring the following directives in your php.ini file: error_reporting = -1 display_errors = On Then restart Apache, and see if you get the same errors displayed. If you don't know where your php.ini file is, create a new script containing only this code and run it. You'll see the path to the file in the first section, under the "loaded configuration file" entry. Sir can i upload the php.ini file in the cpanel?? I'm on the cpanel right now... there's no error in my localhost... but in our website.. http://ocm-pq.org/index.php all my scripts have this kind of error... Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365743 Share on other sites More sharing options...
Christian F. Posted July 31, 2012 Share Posted July 31, 2012 Have you read the thread Pikachu2000 linked to in the first reply? Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365746 Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2012 Share Posted July 31, 2012 Most likely, you have error reporting off on your local machine, and it only appears to work. While developing, error reporting should always be set to the highest level, and set to display all errors. Make sure you have error reporting set up properly on your local machine by configuring the following directives in your php.ini file: error_reporting = -1 display_errors = On Then restart Apache, and see if you get the same errors displayed. If you don't know where your php.ini file is, create a new script containing only this code and run it. You'll see the path to the file in the first section, under the "loaded configuration file" entry. Sir can i upload the php.ini file in the cpanel?? I'm on the cpanel right now... there's no error in my localhost... but in our website.. http://ocm-pq.org/index.php all my scripts have this kind of error... No, the error does exist in your localhost server too. It's not just being reported, or it's being masked by a configuration setting. Make the changes to your LOCAL php.ini file, restart Apache, and see if you don't get the same errors. Quote Link to comment https://forums.phpfreaks.com/topic/266503-headers-already-sent-errors/#findComment-1365748 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.