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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:
<?php
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);
if(!$ret){
echo"Wrong username or password<br>";
//header("location: login.html");}//redirecting page
}
else{
echo "Login Successful.<a href=login_success.php>Click here to
continue</a>";
//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

if($count==1){
return true;}

else{
return false; }
}
ob_flush();//outputting the data in the buffer as heading
?>
<html>
<body>
</body>
</html>



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 www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho