sessions
Posted: Fri Sep 30, 2011 10:40 am
hi,
Why am I getting these errors:
and here is the full code:
Youssef
Why am I getting these errors:
Code: Select all
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/abmxrcom/public_html/cart.php:1) in /home/abmxrcom/public_html/cart.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/abmxrcom/public_html/cart.php:1) in /home/abmxrcom/public_html/cart.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at /home/abmxrcom/public_html/cart.php:1) in /home/abmxrcom/public_html/cart.php on line 53
Code: Select all
<?php
session_start();
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
//Section if they clicked add to Cart this code will activate
if (isset($_POST['Item_Name']))
{
$Item_Name = $_POST['Item_Name'];// Name of the Item
$price = $_POST['price'];// Name of the Item
$shipping = $_POST['shipping'];// Name of the Item
$description = $_POST['description'];// Name of the Item
$image = $_POST['image'];// Name of the Item
$weight = $_POST['weight'];
$wasFound = false;
$i = 0;
// If the cart session variable is not set or cart array is empty
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1)
{
// RUN IF THE CART IS EMPTY OR NOT SET So no thing in the cart
$_SESSION["cart_array"] = array(0 => array("Item_Name" => $Item_Name, "quantity" => 1, "description" => $description, "price" => $price, "image" => $image, "shipping" => $shipping, "weight" => $weight));
}
else
{
// Run if they try to add a duplicate item so the cart is not empty but they are trying to add same item
foreach ($_SESSION["cart_array"] as $each_item)
{
$i++;
while (list($key, $value) = each($each_item))
{
if ($key == "Item_Name" && $value == $Item_Name)
{
// That item is in cart already so let's adjust its quantity using array_splice()
array_splice($_SESSION["cart_array"], $i-1, 1, array(array("Item_Name" => $Item_Name, "quantity" => $each_item['quantity'] + 1, "description" => $description, "price" => $price, "image" => $image, "shipping" => $shipping, "weight" => $weight)));
$wasFound = true;
} // close if condition
} // close while loop
} // close foreach loop
// If the cart is not empty but they are putting a new item
if ($wasFound == false)
{
array_push($_SESSION["cart_array"], array("Item_Name" => $Item_Name, "quantity" => 1, "description" => $description, "price" => $price, "image" => $image, "shipping" => $shipping, "weight" => $weight));
}
}
header("location: cart.php");
exit();
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Section (if user chooses to empty their shopping cart)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
unset($_SESSION["cart_array"]);
}
?>
<?php
//////////////////// Section (if user chooses to adjust item quantity) //////////////////////////
if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "")
{
// execute some code
$item_to_adjust = $_POST['item_to_adjust'];
$Changequantity = $_POST['Changequantity'];
$Changequantity = preg_replace('#[^0-9]#i', '', $Changequantity); // filter everything but numbers
if ($Changequantity >= 100) { $Changequantity = 99; }
if ($Changequantity < 1) { $Changequantity = 1; }
if ($Changequantity == "") { $Changequantity = 1; }
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item)
{
//get the variables from the session array
$Item_Name = $each_item['Item_Name'];
$quantity = $each_item['quantity'];
$description = $each_item['description'];
$price = $each_item['price'];
$image = $each_item['image'];
$eachshipping = $each_item['shipping'];
$weight = $each_item['weight'];
$i++;
while (list($key, $value) = each($each_item))
{
if ($key == "Item_Name" && $value == $item_to_adjust)
{
// That item is in cart already so let's adjust its quantity using array_splice()
array_splice($_SESSION["cart_array"], $i-1, 1, array(array("Item_Name" => $item_to_adjust, "quantity" => $Changequantity, "description" => $description, "price" => $price, "image" => $image, "shipping" => $eachshipping, "weight" => $weight)));
} // close if condition
} // close while loop
} // close foreach loop
}
?>
<?php
////////////////////// Section (if user wants to remove an item from cart) /////////////////////
if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "")
{
// Access the array and run code to remove that array index
$key_to_remove = $_POST['index_to_remove'];
// if on;y one item or non in the cart
if (count($_SESSION["cart_array"]) <= 1)
{
unset($_SESSION["cart_array"]);
}
//else delete that item from the cart
else
{
unset($_SESSION["cart_array"]["$key_to_remove"]);
sort($_SESSION["cart_array"]);
}
}
?>
<?php
///////////////////// output the cart for the user to view /////////////////////
$cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$weightTotal = "";
$ItemsNames = "";// List of the Items Names
$ItemsNamess = "";// List of the items Names and there quantities.
$quantityList = ""; // Is the list of the quantities
$TotalIncDel =""; //total amount of money including shipping
$conclusion = ""; // shipping cost
$FirstpartTable = "";
$SecondpartTable = "";
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1)
{
$cartOutput = '<h2 align="center" style="margin-bottom:30px; margin-top:30px; color:red">Your shopping cart is empty</h2>';
$weightTotal = "";
}
else
{
$FirstpartTable = '
<table width="100%" style="padding:5px; border-collapse:collapse " id="cartTable">
<tr>
<th>Product</th>
<th>Product Description</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Remove</th>
</tr>';
$SecondpartTable = '</table>';
// Start PayPal Checkout Button
$pp_checkout_btn .= '<form target="paypal" action="https://securepayments.paypal.com/acquiringweb" method="post">
<input type="hidden" name="cmd" value="_hosted-payment">
<input type="hidden" name="business" value="CWG4R8U5DZU9S">';
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item)
{
//get the variables from the session array
$Item_Name = $each_item['Item_Name'];
$quantity = $each_item['quantity'];
$description = $each_item['description'];
$price = $each_item['price'];
$image = $each_item['image'];
$eachshipping = $each_item['shipping'];
$weight = $each_item['weight'];
//list of the items names for the form paypal
$ItemsNames = $Item_Name . " , " . $ItemsNames;
$quantityList = $quantity . " , " . $quantityList;
$eachweight = $weight * $quantity; // each item full weight
$weightTotal = $eachweight + $weightTotal; // the total weight
//arrange the price
$pricetotal = $price * $quantity;
$cartTotal = $pricetotal + $cartTotal;
//this line below make UK as our currensy
setlocale(LC_MONETARY, 'en_GB.UTF-8');
//this 2 line below make 10 be 10.00
$pricetotal = money_format("%10.2n", $pricetotal);
$price = money_format("%10.2n", $price);
/* $pp_checkout_btn .= '<input type="hidden" name="item_name" value="' . $Item_Name . ' , ' . $quantity . '">'; */
//output to the user
$cartOutput .= '<tr>';
$cartOutput .= '<td><img style="width:50px; height:66px" src="' . $image . '"/></td>';
$cartOutput .= '<td>' . $description . '</td>';
$cartOutput .= '<td>' . $price . '</td>';
$cartOutput .=
'<td><form action="cart.php" method="post">
<input name="Changequantity" type="text" value="' . $quantity . '" size="1" maxlength="2" />
<input name="item_to_adjust" type="hidden" value="' . $Item_Name . '" />
<input name="adjustBtn' . $Item_Name . '" type="submit" value="change" />
</form></td>';
$cartOutput .= '<td>' . $pricetotal . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post"><input id="cart_Delete_Each" name="deleteBtn' . $Item_Name . '" type="submit" value="DELETE" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; // i target this specific item
$cartOutput .='</tr>';
$i++;
}
$TotalItemsMoney = $cartTotal;
//this line below make UK as our currensy
setlocale(LC_MONETARY, 'en_GB.UTF-8');
//this line below make 10 be 10.00
$cartTotal = money_format("%10.2n", $cartTotal);
////////////////////////////////////// Calculating the shipping begin ///////////////////////////////////////////////
if($weightTotal == 1)
{
$conclusion = 3.85;
}
else if($weightTotal == 2)
{
$conclusion = 3.95;
}
else if($weightTotal == 3)
{
$conclusion = 4.85;
}
else if($weightTotal > 3)
{
$threeKilos = 4.85; // the three kilos shipping cost
$AboveThreeKilos = $weightTotal - 3; //Get how many kilos above the 3 kilos
$AboveThreeKilosCost = $AboveThreeKilos * 0.77; // the above three kilos shipping cost
$conclusion = $AboveThreeKilosCost + $threeKilos;
}
$TotalIncDel = $TotalItemsMoney + $conclusion;
/////////////////////////////////////// Calculating the shipping end ///////////////////////////////////////////////
$uniquenumber = rand(0, 100000000);
$item_replace = "k$uniquenumber";
//ItemsNamess is the item names and quantities for the 3P Logistics
$ItemsNamess = $ItemsNames . " / " . $quantityList;
$pp_checkout_btn .= '
<input type="hidden" name="item_name" value="' . $ItemsNamess . '">
<input type="hidden" name="subtotal" value="' . $TotalItemsMoney . '">
<input type="hidden" name="custom" value="' . $ItemsNamess . '">
<input type="hidden" name="notify_url" value="https://www.ab-mxr.com/ipn.php">
<input type="hidden" name="return" value="https://www.ab-mxr.com">
<input type="hidden" name="invoice" value="' . $item_replace . '">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="https://www.ab-mxr.com">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="shipping" value="' . $conclusion . '">
<input type="hidden" name="currency_code" value="GBP">
<input type="image" src="css/images/ProceedToCheckOut.png" border="0" name="submit">
</form>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="Description" content="abs workout, Six pack abs"/>
<meta name="Keywords" content="Six pack abs, how to get six pack abs, six pack abs workout, six pack abs routine, six pack abs execise, workout program, workout program, workout routine, workout routines"/>
<title>ab-mxr.com fitness | abs | workout| killer crunch | six packs | flat stomach | weight loss | 6 pack | fat loss | fat burner</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<style type="text/css">
#cartTable th {
font-weight:bold;
border:1px black solid;
background:grey;
padding:5px;
}
#cartTable td {
border:1px black solid;
padding:5px;
}
#cart_Delete_Each{
background:none;
border:0;
color: darkRed;
cursor:pointer;
font-weight:bold;
}
</style>
</head>
<body>
<!-- Top -->
<div id="top">
<div style=" background-image:url('css/images/top_Bg.png'); background-repeat:repeat-x">
<div style="width: 980px; margin-left: auto; margin-right: auto;">
<!-- Header -->
<div id="header">
<img style="float:left" src="css/images/logo.png"/>
<div id="navigation">
<table style="width: 100%" >
<tr>
<td id="freephone_Top" ><font style="color: red;">Free</font>phone number: 0800 002 9557</td>
</tr>
<tr>
<td style="text-align:right">
<ul id="log_Reg" style=" ">
<li class="last">Or click <a href="register.php">here</a> to register your interest</li>
</ul>
<a href="http://www.facebook.com/pages/Ab-Mxr/203731912978671"><img id="social_Img" src="css/images/FaceBook.png"/></a>
<a href="http://www.youtube.com/watch?v=ZTIlJit4buY&feature=player_embedded"><img id="social_Img" src="css/images/youtube.png"/></a>
<a style="color:white;" href="http://twitter.com/Secret_Trainer"><img id="social_Img" style="margin-right:0px;" src="css/images/twiter_1.png"/></a>
</td>
</tr>
</table>
</div>
</div>
<!-- End Header -->
<div id="header_Abs_Words">
THE AB-MXR IS AN ABDOMINAL EXERCISE DEVICE, THAT FOCUSES YOUR EFFORTS IN THE RIGHT PLACE AND FACILITATES A FULL BODY WORKOUT, HELPING TO GIVE YOU PERFECT FLAT ABS
</div>
</div>
</div>
</div>
<!-- Top -->
<div class="shell">
<ul id="menu_Ul_Top">
<li onclick=" document.location='index.php'" id="menu_small">HOME</li>
<li onclick=" document.location='about.php'" id="menu_small">ABOUT</li>
<li onclick=" document.location='testimonials.php'" id="menu_big">MEDICAL TESTIMONIALS</li>
<li onclick=" document.location='wantone.php'" id="menu_medium">I WANT ONE</li>
<li onclick=" document.location='theworkout.php'" id="menu_medium">THE WORK OUT</li>
<li onclick=" document.location='fitness.php'" id="menu_big">FITNESS PROFESSIONALS</li>
<li onclick=" document.location='media.php'" id="menu_small">MEDIA</li>
<li onclick=" document.location='contact.php'" id="menu_small">CONTACT</li>
</ul>
</div>
<!-- Main -->
<div style="background-image:url('css/images/all_Content.png');" >
<div class="shell">
<!-- Content -->
<div id="content">
<div>
<div style="text-align:right; padding-bottom:10px;">
<?php echo $pp_checkout_btn ?>
</div>
<!-- <table width="100%" style="padding:5px; border-collapse:collapse " id="cartTable">
<tr>
<th>Product</th>
<th>Product Description</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Remove</th>
</tr>
-->
<?php echo $FirstpartTable ?>
<?php echo $cartOutput ?>
<?php echo $SecondpartTable ?>
<!--</table>
-->
<div style=" padding-top:10px; margin-bottom:30px; overflow:hidden; width:100%">
<div style="float:left">
<div style="margin-bottom:10px;"><a href="https://www.ab-mxr.com/wantone.php"><strong style="color: darkRed;">Continue Shopping</strong></a></div>
<div style="margin-bottom:10px;"><a href="cart.php?cmd=emptycart"><strong style="color: darkRed;">Empty Your Shopping Cart</strong></a></div>
<img src="css/images/MasterCard.png"/> <img src="css/images/Paypal.png"/> <img src="css/images/Visa.png"/>
</div>
<div style="float:right">
<strong style="width:130px; display: inline-block;">SUBTOTAL:</strong> <?php echo $cartTotal; ?><br/><br/>
<strong style="width:130px; display: inline-block;">Delivery:</strong> £<?php echo $conclusion ?><br/><br/>
<strong style="width:130px; display: inline-block;">TOTAL INC DELIVERY:</strong> £<?php echo $TotalIncDel; ?><br/><br/>
<strong style="width:130px; display: inline-block;">Products Weight:</strong> <?php echo $weightTotal ?> kg<br/><br/>
<?php echo $pp_checkout_btn ?></div>
</div>
</div>
</div>
<!-- Content -->
<!--footer Begin -->
<?php include_once "includes/footer.php";?>
<!--footer End -->
</div>
</body>
</html>