PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/users/modelair/modelaircraft.co.nz/htdocs/db.php:48) in /var/users/modelair/modelaircraft.co.nz/htdocs/db.php on line 41
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/users/modelair/modelaircraft.co.nz/htdocs/db.php:48) in /var/users/modelair/modelaircraft.co.nz/htdocs/db.php on line 41
<?php
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc
$dbServer = "***";
$dbUser = "***";
$dbPass = "***";
$dbName = "models";
function ConnectToDb($server, $user, $pass, $database)
{
// Connect to the database and return
// true/false depending on whether or
// not a connection could be made.
$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);
if(!$s || !$d)
return false;
else
return true;
}
function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID
session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
?>
white-space or any other amount of character output will result (generally) in header's already sent errors. You need to alter your script so it doesn't print anything until all your headers are set up. I know someone will suggest [php_man]ob_start[/php_man], that's not the point though.