| |||||||||||
| |||||||||||
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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |