Session for creating a unique shopping cart for each user

From: Tore E. Mackay (tore_at_temweb.net)
Date: 10/31/03


To: php-general@lists.php.net
Date: Fri, 31 Oct 2003 15:47:13 +0100

Hi,

I am creating a shopping cart but experiensing some difficulty in creating
unique shopping carts for each user. When I try to create a session I get
this error message:
Warning: session_start(): Cannot send session cookie - headers already sent

This is the code:
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
session_start();
session_register("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}

If I remove the session_start() and session_register it works fine, but then
everyone uses the same cart and that can't be good.

Thanx!!!

Regards
Tore



Relevant Pages

  • four or five shopping cart design questions
    ... I'm thinking about building a shopping cart from scratch, ... How does repeat customer session handling usually work? ... they have to supply name address and credit card number. ... the shoppingMode screens, do we NULL out the credit card in ...
    (comp.lang.php)
  • SessionID Still not working
    ... I have written a shopping cart using ASP .NET. ... The session ID is supposed to stay the same!!! ... IIS 6.0 W2K3 server and updated patches. ... that displays the sessionid on the top of the page, and it changes when I hit ...
    (microsoft.public.dotnet.framework.aspnet)
  • Session ID is changing
    ... I have written a shopping cart using ASP .NET. ... The session ID is supposed to stay the same!!! ... IIS 6.0 W2K3 server and updated patches. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: four or five shopping cart design questions
    ... > I'm thinking about building a shopping cart from scratch, ... > 2) How does repeat customer session handling usually work? ... > they have to supply name address and credit card number. ...
    (comp.lang.php)
  • Re: URGENT ssl/cookie problem
    ... > we get two copies of our shopping cart session cookie generated - one under ... > How do I delete both session cookies from inside one url? ... between http and https pages of *same domain*. ...
    (comp.lang.php)