Log in

View Full Version : Warning: Cannot modify header information



jonnyfreak
06-10-2013, 10:54 AM
I have been looking through the forum regarding this a alot of peoples problems are white space or the session needs to go at the top of the page before ANYTHING else.

i am getting the following errors


Warning: Cannot modify header information - headers already sent by (output started at /homepages/6/d330188495/htdocs/beta/shopping-cart.php:1) in /homepages/6/d330188495/htdocs/beta/shopping-cart.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /homepages/6/d330188495/htdocs/beta/shopping-cart.php:1) in /homepages/6/d330188495/htdocs/beta/shopping-cart.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /homepages/6/d330188495/htdocs/beta/shopping-cart.php:1) in /homepages/6/d330188495/htdocs/beta/shopping-cart.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /homepages/6/d330188495/htdocs/beta/shopping-cart.php:1) in /homepages/6/d330188495/htdocs/beta/shopping-cart.php on line 5

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /homepages/6/d330188495/htdocs/beta/shopping-cart.php:1) in /homepages/6/d330188495/htdocs/beta/XCInc/XCart.inc on line 4

the code i have in the page is (starting at line 1)


<?php require_once('Connections/lotties.php');
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache");

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE LOTTIE_voucher SET vouchCode=%s WHERE vouchID=%s",
GetSQLValueString($_POST['vouchCode'], "text"),
GetSQLValueString($_POST['vouchID'], "int"));

mysql_select_db($database_lotties, $lotties);
$Result1 = mysql_query($updateSQL, $lotties) or die(mysql_error());
}


// *** X Shopping Cart ***
$useSessions = true;
$XCName = "LottieJakeCart";
$XCTimeout = 30;
$XC_ColNames=array("ProductID","Quantity","Name","Price","Stock","Total");
$XC_ComputedCols=array("","","","","","Price");
require_once('XCInc/XCart.inc');

mysql_select_db($database_lotties, $lotties);
$query_rsVoucher = "SELECT * FROM LOTTIE_vouchercode";
$rsVoucher = mysql_query($query_rsVoucher, $lotties) or die(mysql_error());
$row_rsVoucher = mysql_fetch_assoc($rsVoucher);
$totalRows_rsVoucher = mysql_num_rows($rsVoucher);

// *** Update contents of Shopping Cart ***
require_once('XCInc/XCupdateAction.inc');
if (isset($_POST["Quantity"])) {
$XC_UpdateRedirect = "shopping-cart.php";
$values = $_POST["Quantity"];
require_once('XCInc/UpdateXCart.inc');
}

// *** Empty XCart ***
if (isset($_SERVER["QUERY_STRING"])) {
$XC_EmptyCartLink = $_SERVER["PHP_SELF"] . "?" . htmlentities($_SERVER["QUERY_STRING"]) . "&XC_EmptyCart=1";
} else {
$XC_EmptyCartLink = $_SERVER["PHP_SELF"] . "?XC_EmptyCart=1";
}
if (isset($_GET["XC_EmptyCart"]) && ($_GET["XC_EmptyCart"] == "1")) {
$XC_EmptyCartRedirect = "shopping-cart.php";
require_once('XCInc/XCemptyRedirect.inc');
}

// *** Repeat XCart region *** (do not remove this label)

// voucher code
if (isset($_POST['vouchCode']) && $_POST['vouchCode'] == $row_rsVoucher['VCode']) {
$mycode = $row_rsVoucher['VCode'];
$spos = strpos($mycode, "c");
if ($spos !== false) {
$myvalue = substr($mycode, $spos+1);
$myvalue = $XCart_sumTotal * $myvalue / 100;
} else {
$spos = strpos($mycode, "p");
if ($spos !== false) {
$myvalue = substr($mycode, $spos+1);
}
}
$myTotal = $XCart_sumTotal - $myvalue;
$_SESSION['vouchCode'] = $myvalue;
} else unset($_SESSION['vouchCode']);

function DoFormatCurrency($num,$dec,$sdec,$sgrp,$sym,$cnt) {
setlocale(LC_MONETARY, $cnt);
if ($sdec == "C") {
$locale_info = localeconv();
$sdec = $locale_info["mon_decimal_point"];
$sgrp = $sgrp!="" ? $locale_info["mon_thousands_sep"] : "";
$sym = $cnt!="" ? $locale_info["currency_symbol"] : $sym;
}
$thenum = $sym.number_format($num,$dec,$sdec,$sgrp);
return $thenum;
}
?>


the code is the shopping cart with the ability to add a discount vouchers for example

lot123p10

would be %10 of the total

can anyone advise me please

thanks in advance

Beverleyh
06-10-2013, 12:20 PM
My first thought was to do with BOM, so I started formulating an answer;


Could be down to file encoding? BOM characters can sometimes be introduced at the start of your file depending on how your editor is setup to handle file encoding. For example, UTF-8 can insert something that looks like "  " right before the opening <?php tag, so try saving it in ANSI format. In Windows you can do that in good ol' Notepad - File >> Save As >> click the Encoing: dropdown and choose ANSI.

Then I wondered about the require_once "Connection/lotties.php" file and the "shopping-cart.php" file that its pulling in, so I Googled them to see if I could download a copy to examine. I found your post in another forum: http://forums.phpfreaks.com/topic/278983-mutliple-warning-cannot-modify-header-information/

I see that you are already receiving help from there so I will leave the guys over at the other forum to assist you further. It just makes more sense than having us all spend time on the same issue.

jonnyfreak
06-10-2013, 12:56 PM
My first thought was to do with BOM, so I started formulating an answer;



Then I wondered about the require_once "Connection/lotties.php" file and the "shopping-cart.php" file that its pulling in, so I Googled them to see if I could download a copy to examine. I found your post in another forum: http://forums.phpfreaks.com/topic/278983-mutliple-warning-cannot-modify-header-information/

I see that you are already receiving help from there so I will leave the guys over at the other forum to assist you further. It just makes more sense than having us all spend time on the same issue.

yes sorry about that. i got it sorted regarding the BOM. thanks for your time. i don't know what's best to do in this circumstance (should i edit this post to show the answer?) or try to stick to one forum?

traq
06-10-2013, 02:51 PM
Nothing to be sorry about. Posting on multiple forums, IMO, is perfectly acceptable - as long as you're not just spamming to see who will do the work for you fastest. (Not an accusation; just a contrasting example :).)

If you've got a solution, then yeah, post it here too. It makes the thread more helpful to future readers.