Hi everyone,
Is there a way to use a nested include in PHP without having the nested include automatically send the headers back to the browser?
For example, I have a PHP file called test.php that has a reference to an include file called createCookie.php:
<?php
include($_SERVER['DOCUMENT_ROOT'] . "/includes/createCookie.php");
$CartID = createCookie();
echo $CartID;
?>
Then within the include file createCookie.php, I reference a nested include file called openDatabase.php in the function createCookie():
<?php
function createCookie()
{
if(!isset($CartID))
{
virtual($_SERVER['DOCUMENT_ROOT'] . "/includes/openDatabase.php");
$GetCurrentShoppingCartIDSQL = "SELECT ShoppingCartID FROM Increment";
$ShoppingCartIDRow = mysql_query($GetCurrentShoppingCartIDSQL, $DbConnection);
while($ShoppingCartIDResults = mysql_fetch_array($ShoppingCartIDRow))
{
$ShoppingCartID = $ShoppingCartIDResults["ShoppingCartID"];
}
$NewShoppingCartID = $ShoppingCartID + 1;
$UpdateShoppingCartIDSQL = "UPDATE Increment SET ShoppingCartID = " . $NewShoppingCartID;
if (!(@ mysql_query ($UpdateShoppingCartIDSQL, $DbConnection)))
echo "Database Error";
//Set the cookie
setcookie("CartID", $NewShoppingCartID, time()+259200, "/", "", 0);
mysql_close($DbConnection);
$CartID = $NewShoppingCartID;
}
else
{
$CartID = 0;
}
return($CartID);
}
?>
When I attempt to execute the test.php file however, I have a problem with the headers already being outputted. Is there a way the nested include can be used without error?
Thanks,
Ryan