Forum Moderators: coopster

Message Too Old, No Replies

setcookie() problem

         

bagheera

6:54 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



I have a 'easy' problem I think but cannot get over it somehow...

I get the classical:

Warning: Cannot modify header information - headers already sent by (output started at /wn/show_item_list.php:6) in /wn/scripts/db2.php on line 25

my code is as follows:

for - show_item_list.php -

<?php include("db2.php");?>
<html>
<head>
<title>Order Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.boxes {...
....
...html stuff

for - db2.php -

<?php
// This page contains the connection routine for the
// database as well as getting the ID of the cart, etc
session_start();
$connection=mysql_connect("host", "dbuser", "dbpass")
or die(mysql_error());
mysql_select_db("DB", $connection);

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
setcookie("CartID", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
?>

The db2.php is at the top of the show_item_list.php - so I do not send anything (html code, or echo's ) to the browser - Im new so I might have missed something?

Thanks,

Warboss Alex

7:17 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



Even extra whitespace in your files counts as 'output' to the browser, y'sure there's none in the file?

bagheera

7:39 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



No - ive checked no whitespaces...

jatar_k

7:45 pm on Mar 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what code is here

/wn/scripts/db2.php on line 25

bagheera

7:54 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



db2.php line 25:
setcookie("CartID", session_id(), time() + ((3600 * 24) * 30));

in show_item_list.php line 6 is:
<style type="text/css">

And there is nothing outputed to the browser...