session_start() errors on form submit

Hi everyone,

I'm getting the following errors when I submit a contact form, however the contents of the form do get submitted successfully:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/consumer/contact.php on line 129

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/consumer/contact.php on line 129

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/webassist/email/mail_php.php on line 285

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/webassist/email/mail_php.php on line 285

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/consumer/contact.php on line 159

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/consumer/contact.php on line 159

Warning: Cannot modify header information - headers already sent by (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/consumer/contact.php on line 161

The code in code view below is what is appearing above the docType in my document.

I wondered if someone could take a quick look to see why all these errors are appearing.

Appreciate any help.
<?php require_once("../includes/newsletter.php"); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once("../WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("../WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php 
if (isset($_POST["submit"]))  {
  $WAFV_Redirect = "";
  $_SESSION['WAVT_index_965_Errors'] = "";
  if ($WAFV_Redirect == "")  {
    $WAFV_Redirect = $_SERVER["PHP_SELF"];
  }
  
  $WAFV_Errors = "";
  $WAFV_Errors .= WAValidateRQ(((isset($_POST['firstname']) && $_POST['firstname'] != "First Name")?$_POST['firstname']:"") . "",false,1);
  $WAFV_Errors .= WAValidateRQ(((isset($_POST['lastname']) && $_POST['lastname'] != "Last Name")?$_POST['lastname']:"") . "",false,2);
  $WAFV_Errors .= WAValidateEM(((isset($_POST["email"]))?$_POST["email"]:"") . "",true,3);

  if ($WAFV_Errors != "")  {
    PostResult($WAFV_Redirect,$WAFV_Errors,"index_965");
  }
}
?>
<?php 
// WA Application Builder Insert
if (isset($_POST["submit"])) // Trigger
{
  $WA_connection = $newsletter;
  $WA_table = "subscriptions";
  $WA_sessionName = "subscriptions_subID";
  $WA_redirectURL = "?sent=true";
  $WA_keepQueryString = false;
  $WA_indexField = "subID";
  $WA_fieldNamesStr = "firstname|lastname|email";
  $WA_fieldValuesStr = "".((isset($_POST["firstname"]))?$_POST["firstname"]:"")  ."" . "|" . "".((isset($_POST["lastname"]))?$_POST["lastname"]:"")  ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"")  ."";
  $WA_columnTypesStr = "',none,''|',none,''|',none,''";
  $WA_fieldNames = explode("|", $WA_fieldNamesStr);
  $WA_fieldValues = explode("|", $WA_fieldValuesStr);
  $WA_columns = explode("|", $WA_columnTypesStr);
  $WA_connectionDB = $database_newsletter;
  mysql_select_db($WA_connectionDB, $WA_connection);
  if (!session_id()) session_start();
  $insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
  $WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
  $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
  $_SESSION[$WA_sessionName] = mysql_insert_id();
  if ($WA_redirectURL != "")  {
    if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
      $WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
    }
    header("Location: ".$WA_redirectURL);
  }
}
?>

<?php require_once("../WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("../WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php 
if (isset($_POST["SimpleContact_submit"]))  {
  $WAFV_Redirect = "contact.php?invalid=true";
  $_SESSION['WAVT_contact_Errors'] = "";
  if ($WAFV_Redirect == "")  {
    $WAFV_Redirect = $_SERVER["PHP_SELF"];
  }
  $WAFV_Errors = "";
  $WAFV_Errors .= WAValidateRQ((isset($_POST["Contact_us_group_Name"])?$_POST["Contact_us_group_Name"]:"") . "",true,1);
  $WAFV_Errors .= WAValidateEM((isset($_POST["Contact_us_group_Email"])?$_POST["Contact_us_group_Email"]:"") . "",true,2);
  $WAFV_Errors .= WAValidateRQ((isset($_POST["Contact_us_group_Comments"])?$_POST["Contact_us_group_Comments"]:"") . "",true,3);

  if ($WAFV_Errors != "")  {
    PostResult($WAFV_Redirect,$WAFV_Errors,"contact");
  }
}
?>
<?php require_once("../webassist/email/mail_php.php"); ?>
<?php require_once("../webassist/email/mailformatting_php.php"); ?>
<?php
if (!isset($_SESSION))session_start();
if ((isset($_POST["SimpleContact_submit"])))     {
  //WA Universal Email object="mail"
  set_time_limit(0);
  $EmailRef = "waue_contact_3";
  $BurstSize = 200;
  $BurstTime = 1;
  $WaitTime = 1;
  $GoToPage = "contact.php?sent=true";
  $RecipArray = array();
  $StartBurst = time();
  $LoopCount = 0;
  $TotalEmails = 0;
  $RecipIndex = 0;
  // build up recipients array
  $CurIndex = sizeof($RecipArray);
  $RecipArray[$CurIndex] = array();
  $RecipArray[$CurIndex ][] = "test@test.com";
  $TotalEmails += sizeof($RecipArray[$CurIndex]);
  $RealWait = ($WaitTime<0.25)?0.25:($WaitTime+0.1);
  $TimeTracker = Array();
  $TotalBursts = floor($TotalEmails/$BurstSize);
  $AfterBursts = $TotalEmails % $BurstSize;
  $TimeRemaining = ($TotalBursts * $BurstTime) + ($AfterBursts*$RealWait);
  if ($TimeRemaining < ($TotalEmails*$RealWait) )  {
    $TimeRemaining = $TotalEmails*$RealWait;
  }
  $_SESSION[$EmailRef."_Total"] = $TotalEmails;
  $_SESSION[$EmailRef."_Index"] = 0;
  $_SESSION[$EmailRef."_Remaining"] = $TimeRemaining;
  while ($RecipIndex < sizeof($RecipArray))  {
    $EnteredValue = is_string($RecipArray[$RecipIndex][0]);
    $CurIndex = 0;
    while (($EnteredValue && $CurIndex < sizeof($RecipArray[$RecipIndex])) || (!$EnteredValue && $RecipArray[$RecipIndex][0])) {
      $starttime = microtime_float();
      if ($EnteredValue)  {
        $RecipientEmail = $RecipArray[$RecipIndex][$CurIndex];
      }  else  {
        $RecipientEmail = $RecipArray[$RecipIndex][0][$RecipArray[$RecipIndex][2]];
      }
      $EmailsRemaining = ($TotalEmails- $LoopCount);
      $BurstsRemaining = ceil(($EmailsRemaining-$AfterBursts)/$BurstSize);
      $IntoBurst = ($EmailsRemaining-$AfterBursts) % $BurstSize;
      if ($AfterBursts<$EmailsRemaining) $IntoBurst = 0;
      $TimeRemaining = ($BurstsRemaining * $BurstTime * 60) + ((($AfterBursts<$EmailsRemaining)?$AfterBursts:$EmailsRemaining)*$RealWait) - (($AfterBursts>$EmailsRemaining)?0:($IntoBurst*$RealWait));
      if ($TimeRemaining < ($EmailsRemaining*$RealWait) )  {
        $TimeRemaining = $EmailsRemaining*$RealWait;
      }
      $CurIndex ++;
      $LoopCount ++;
      session_commit();
      session_start();
      $_SESSION[$EmailRef."_Index"] = $LoopCount;
      $_SESSION[$EmailRef."_Remaining"] = round($TimeRemaining);
      session_commit();
      wa_sleep($WaitTime);
      include("../webassist/email/waue_contact_3.php");
      $endtime = microtime_float();
      $TimeTracker[] =$endtime - $starttime;
      $RealWait = array_sum($TimeTracker)/sizeof($TimeTracker);
      if ($LoopCount % $BurstSize == 0)  {
        $TimePassed = (time() - $StartBurst);
        if ($TimePassed < ($BurstTime*60))  {
          $WaitBurst = ($BurstTime*60) -$TimePassed;
          wa_sleep($WaitBurst);
        }
        else  {
          $TimeRemaining = ($TotalEmails- $LoopCount)*$RealWait;
        }
        $StartBurst = time();
      }
      if (!$EnteredValue)  {
        $RecipArray[$RecipIndex][0] =  mysql_fetch_assoc($RecipArray[$RecipIndex][1]);
      }
    }
    $RecipIndex ++;
  }
  $_SESSION[$EmailRef."_Total"] = 0;
  $_SESSION[$EmailRef."_Index"] = 0;
  $_SESSION[$EmailRef."_Remaining"] = 0;
  session_commit();
  session_start();
  if ($GoToPage!="")     {
    header("Location: ".$GoToPage);
  }
}
?>
<?php
define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']); 
include_once(__ROOT__ . "/includes/helpers.inc.php");
include_once(__ROOT__ . "/includes/config.inc.php");
 ?>

Open in new window

LVL 1
gwh2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
<?php require_once("../includes/newsletter.php"); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>


means that you have already a newline in the output, which is between the ?> and the <?php
which is the main problem.

note that really your page should start:

<?php session_start() ; ?>
<?php require_once("../includes/newsletter.php"); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>


for:
Warning: Cannot modify header information - headers already sent by (output started at /home/site/www/www/consumer/contact.php:56) in /home/site/www/www/consumer/contact.php on line 161

the line indicated is where your output happens ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shinesh PremrajanEngineering ManagerCommented:
pls check the following include files

<?php require_once("../WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>

there is some out output coming from this page.

Hope this helps
0
gwh2Author Commented:
Thanks for the replies,

Sorry I'm a bit confused.

<< means that you have already a newline in the output, which is between the ?> and the <?php
which is the main problem. >>

Are you saying I should look in WA_AppBuilder_PHP.php for a blank line?
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

gwh2Author Commented:
The contents of WAVT_ValidatedForm_PHP.php is below. There doesn't seem to be any blank lines in that file either.
<?php
if (!session_id())  {
  session_start();
}
function ValidatedField($page,$field)  {
  $theFields= "";
  $retVal = "";
  if (isset($_SESSION["WAVT_".$page."_Errors"]))  {
    $theFields = "&".$_SESSION["WAVT_".$page."_Errors"];
  }
  if (strpos($theFields,"&WAVT_".$field."=") !== false)  {
    $retVal = substr($theFields,strpos($theFields,"&WAVT_".$field."=")+strlen("&WAVT_".$field."="));
  }
  if (strpos($retVal,"&WAVT_") !== false)  {
    $retVal = substr($retVal,0,strpos($retVal,"&WAVT_"));
  }
  if ($retVal == "" && $page == $field) {
    $retVal = ValidatedField($page,$field."_Errors");
  }
  return $retVal;
}
?>

Open in new window

0
rajkumar_pbCommented:
Change this
[code]
<?php require_once("../includes/newsletter.php"); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
[/code]

to
[code]
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once("../includes/newsletter.php"); ?>
[/code]

It'll work. Since the AppBilder_php already has  a session_start it throws that error, as the you're trying to pass the header before the session_start.
(i guess the newsletter.php doesnt have any session_start line in it.)
0
gwh2Author Commented:
I ended up just having to remove some blank lines in my main document and for some reason this eliminated the errors.

Thanks again for the replies
0
rajkumar_pbCommented:
^^ Good that you got it work.
0
Julian HansenCommented:
Why don't you put your session_start() at the top of the page before all the includes?
0
gwh2Author Commented:
Yeah doing that probably would have helped also.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.