Re: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
- From: trookat <trookat@xxxxxxxxxxxxx>
- Date: Sat, 28 Feb 2009 10:33:25 +0900
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
.
- References:
- Prev by Date: Re: Possibility to run perl script in php code
- Next by Date: OT: Re: Possibility to run perl script in php code
- Previous by thread: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
- Next by thread: Re: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
- Index(es):
Relevant Pages
|