Error with cookie

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!

Moderator: General Moderators

Post Reply
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Error with cookie

Post by wizzard »

Warning: Cannot add header information - headers already sent by (output started at /usr/local/psa/home/vhosts/xxxxx.com/httpdocs/dmd/header.php:26) in /usr/local/psa/home/vhosts/xxxxx.com/httpdocs/dmd/cart.php on line 12


Thats the function:

function GetCartId()
{
if(isset($_COOKIE["cartid"]))
{
return $_COOKIE["cartid"];
}
else
{
session_start();
setcookie("cartid", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}


Don't know whats wrong with this:

setcookie("cartid", session_id(), time() + ((3600 * 24) * 30));

Can someone helps me?

Cheerz
Kris
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have a read of:
viewtopic.php?t=1157

Mac
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

setcookie("cartid", session_id(), time() + ((3600 * 24) * 30));

i always get an error first. Then it makes the cookie and i don't have an error anymore.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you read the stickie I linked to above? It explains what causes this error.

Mac
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

Thanks it works now strange you cannot call the function getcartid after there is already code send to the browser.

Regards
Kris
Post Reply