Re: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent



Co wrote:
Hi,

I get this famous message when I run my register.php. page.
Someone tries to register on my website but forgets to fill some
fields. The error control detects it and sends the user back to the
register.php page. That is when the error occurs because the session
has already been started and the header was already send the first
time when output was put to the screen saying:

if(!$first_name){
echo "Voornaam is een verplicht veld. Vul het alsnog in.<br />";
}

Start of register.php:

<?php
session_start() ; ob_start() ;

if ($_SESSION['email_address'] != "" ) {
echo "<b>You do not have the appropriate permissions to enter new
distributors.</b><br><br><br>";


User will be send back when error check fails:

/* Do some error checking on the form posted fields */

if(empty($_POST['first_name']) || empty($_POST['last_name']) || empty
($_POST['email_address']) || empty($_POST['username']) || empty($_POST
['gsm'])){
//if((!$first_name) || (!$last_name) || (!$email_address) || (!
$username) || (!$gsm)){

if(!$first_name){
echo "Voornaam is een verplicht veld. Vul het alsnog in.<br />";
}
if(!$last_name){
echo "Achternaam is een verplicht veld. Vul het alsnog in.<br />";
}
if(!$email_address){
echo "E-mail adres is een verplicht veld. Vul het alsnog in.<br />";
}
if(!$username){
echo "Gebruikersnaam is een verplicht veld. Vul het alsnog in.<br /
";
}
if($_POST['sms'] == 'ja'){
echo "Vul je mobiele nummer in om SMS te kunnen ontvangen.<br />";
}

include 'register.php'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}

How can this be prevented?

Marco


first try placing ob_start(); before session_start();
ob_start can only cache the output after it has been called.

regards
trookat
.



Relevant Pages

  • Warning: session_start() [function.session-start]: Cannot send session cache limiter - heade
    ... Someone tries to register on my website but forgets to fill some ... The error control detects it and sends the user back to the ... echo "Gebruikersnaam is een verplicht veld. ... exit(); // if the error checking has failed, ...
    (comp.lang.php)
  • Re: Newbie Three
    ... echo "tesgform"; ... echo "suspected alien invasion case topic table"; ... echo "suspected alien invasion unknown group name"; ...
    (comp.lang.php)
  • Newbie Three
    ... echo "tesgform"; ... echo "suspected alien invasion case topic table"; ... echo "suspected alien invasion unknown group name"; ...
    (comp.lang.php)
  • ToDo list utility - suggestions/optimizations/refinements wanted
    ... For the past couple of days, I've been working on this todo list script and I'm really happy with the way it works, but wanted to post it here before I go any futher, in case anybody had suggestions for optimizations or style errors. ... echo "File written successfully." ...
    (comp.unix.shell)
  • Re: Shell Script to Remove Old Files
    ... Note it needs a TSM server: ... # Verify command line arguments ... echo "\nError: $STARTDIR does not exist.\n" ...
    (comp.unix.admin)