Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
ob_start() is inactive !!

Posted by shotos (shotos), 13 June 2008
Hi y'all,
i just started with PHP and just came face to face with the dreaded warning:
"Cannot modify header information - headers already sent"

i search and got to know abt output buffering but the functions
ob_start() and ob_flush() are inactive in my php script.

help will be welcomed.......tanx

below is the code:
ob_start();// enabling output bufferring
include("database.php");//including the database connection
//verifying if inputs were supplied
$username = $_POST['username'];
$password = $_POST['password'];

if($username == ''){ unset($username); echo "No username submitted<br>";}
if($password == ''){ unset($password); echo "No password entered<br>";}

if (isset($username) && isset($password))
$ret = confirmUser($username, $password);
echo"Wrong username or password<br>";
//header("location: login.html");}//redirecting page
echo "Login Successful.<a href=login_success.php>Click here to
//header("location: login_success.php");
} else
header("location: login.html");

function confirmUser($username, $password){
global $link;
//checking user inputs
$username = trim($username);
$password = trim($password);
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

//selecting table and confirming username and password
$query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query, $link);
$count = mysql_num_rows($result);//real validation with rows affected by query

return true;}

return false; }
ob_flush();//outputting the data in the buffer as heading

Posted by admin (Graham Ellis), 14 June 2008
Personally, I feel that output buffering is a sticky-plaster fix to poor coding, and I would recommend that you make any header calls you need prior to doing any prints or echos.   Far better to save all your results into variables and substitute them ino the output page - it leads you towards an application whre the look and feel are kept apart from the logic, allowing you to use the same look and feel all across your site, and / or to change your look and feel without having to alter the logic.  It's what the big boys like Google do o change their front page !

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho