Note that there are some explanatory texts on larger screens.

plurals
  1. POWarning: Cannot modify header information - headers already sent by
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1912029/warning-cannot-modify-header-information-headers-already-sent-by-error">&ldquo;Warning: Cannot modify header information - headers already sent by&rdquo; error</a> </p> </blockquote> <p>Hi All, </p> <p>I keep having a warning message appear when I try login. Can you help me rectify the problem.</p> <pre><code>Warning: Cannot modify header information - headers already sent by (output started at /path/to/login.php:15) in /path/to/login.php on line 231 </code></pre> <p>here's the php code before the html: </p> <pre><code>&lt;?php //allow sessions to be passed so we can see if the user is logged in session_start(); //connect to the database so we can check, edit, or insert data to our users table $con = mysql_connect('XXXXXXXXXXXXXXX', 'XXXXXXXXXXXX', 'XXXXXXXXXX') or die(mysql_error()); $db = mysql_select_db('XXXXXXXXXXXXXXXXX', $con) or die(mysql_error()); //include out functions file giving us access to the protect() function made earlier include "functions.php"; ?&gt; </code></pre> <p>Here is the functions.php file: </p> <pre><code>&lt;?php function protect($string){ $string = trim(strip_tags(addslashes($string))); return $string; } ?&gt; </code></pre> <p>and finally here is the PHP inside the HTML:</p> <pre><code>&lt;?php //If the user has submitted the form if($_POST['submit']){ //protect the posted value then store them to variables $username = protect($_POST['username']); $password = protect($_POST['password']); //Check if the username or password boxes were not filled in if(!$username || !$password){ //if not display an error message echo "&lt;center&gt;You need to fill in a &lt;b&gt;Username&lt;/b&gt; and a &lt;b&gt;Password&lt;/b&gt;!&lt;/center&gt;"; }else{ //if the were continue checking //select all rows from the table where the username matches the one entered by the user $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'"); $num = mysql_num_rows($res); //check if there was not a match if($num == 0){ //if not display an error message echo "&lt;center&gt;The &lt;b&gt;Username&lt;/b&gt; you supplied does not exist!&lt;/center&gt;"; }else{ //if there was a match continue checking //select all rows where the username and password match the ones submitted by the user $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."'"); $num = mysql_num_rows($res); //check if there was not a match if($num == 0){ //if not display error message echo "&lt;center&gt;The &lt;b&gt;Password&lt;/b&gt; you supplied does not match the one for that username!&lt;/center&gt;"; }else{ //if there was continue checking //split all fields fom the correct row into an associative array $row = mysql_fetch_assoc($res); //check to see if the user has not activated their account yet if($row['active'] != 1){ //if not display error message echo "&lt;center&gt;You have not yet &lt;b&gt;Activated&lt;/b&gt; your account!&lt;/center&gt;"; }else{ //if they have log them in //set the login session storing there id - we use this to see if they are logged in or not $_SESSION['uid'] = $row['id']; //show message echo "&lt;center&gt;You have successfully logged in!&lt;/center&gt;"; //update the online field to 50 seconds into the future $time = date('U')+50; mysql_query("UPDATE `users` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); //redirect them to the usersonline page header('Location: usersOnline.php'); } } } } } ?&gt; </code></pre> <p>The main issue arises when I try redirect them to my usersOnline.php page.</p> <pre><code>//redirect them to the usersonline page header('Location: usersOnline.php'); </code></pre> <p>I have minimised all white space, but still have problems. Where the error informs me, line 15 is my meta id's (Description &amp; Keywords - SEO). Does this pose problems in PHP?</p> <p>Any help given is much appreciated as I am relatively new with PHP. </p> <p>Thanks, Darren</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload