[SOLVED] PHP session and header redirect problem... HMm

Here is the code for the top of the “customise.php” page.

[code]

<?php require_once('../Connections/DM_database.php'); ?> <?php include_once("../includes/functions.php"); ?> <?php if (isset($_GET["Product_ID"])) { $ProductID = $_GET["Product_ID"]; } elseif (isset($_POST["Product_ID"])) { $ProductID = $_POST["Product_ID"]; $_GET["Product_ID"] = $ProductID; } else { $_GET["Product_ID"] = "1"; $ProductID = $_GET["Product_ID"]; } ?> <?php if (isset($_POST['AddToCart'])) { $qty = "1"; $newstring = ""; $i = 1; foreach ($_POST["Component_ID"] as $type => $component) { if ($i == 1) { $newstring = $component; ++$i; } else { $newstring = $newstring . ", " .$component; } } $query = "INSERT INTO tblshoppingcart (`Cookie_ID`, `Product_ID`, `Component_ID`, `qty`) VALUES ('" . GetCartId() . "', " . intval($ProductID) . ", '" . $newstring . "', " . intval($qty) . ")"; mysql_query($query) or die("query='$query '
".mysql_error()); header("Location: cart.php"); } else {[/code] The function "GetCartId()" does the following: [code]<?php function GetCartId() { if(isset($_COOKIE["sc_ID"])) { return $_COOKIE["sc_ID"]; } else { session_start(); setcookie("sc_ID", session_id(), time() + ((3600 * 24) * 7)); return session_id(); } } ?>[/code]

The Error message I got when I first try to submit the form … With no seesion or cookie set:

[code]Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:wampwwwshopping_cartshopping_cartcustomize.php:10) in C:wampwwwshopping_cartincludesfunctions.php on line 12

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:wampwwwshopping_cartshopping_cartcustomize.php:10) in C:wampwwwshopping_cartincludesfunctions.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwshopping_cartshopping_cartcustomize.php:10) in C:wampwwwshopping_cartincludesfunctions.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwshopping_cartshopping_cartcustomize.php:10) in C:wampwwwshopping_cartshopping_cartcustomize.php on line 26[/code]

The error message I get after I try the process again is:

Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwshopping_cartshopping_cartcustomize.php:10) in C:wampwwwshopping_cartshopping_cartcustomize.php on line 26

NO output before header or session, not even witespace.
any blank or linefeed outside <?php ?> is output.

[code]<?php
require_once(’…/Connections/DM_database.php’);
include_once("…/includes/functions.php");

if (isset($_GET[“Product_ID”])) { $ProductID = $_GET[“Product_ID”];
[/code]

Like always… YOUR RIGHT! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service