Creating Session
Posted: Sat Jun 21, 2003 7:56 am
Hi,
I'm making a webshop and are gonna use session to register products that the customer put in his cart.
The products are going to be registered like this. When clicking the button to buy a products, it sends the product number with it in the link.
The add script i then gonna make a session that has this product number. The first session registered are going to be called 1, and will have the product number in it. When buying a second product the script checks if 1 allready is registered, and if it is, it increases the variable to 2, and so on.
The problem is have to make this work? Increasing the name on tha variable created?
This is what I've done so far since I can't get any further
As you see when I register number, the variable are going to be named number, and not 1 as I want it to. I want the variable that are beeing registered to be named 1, and have the products number in it. This seems kind of hard to do....
I'm making a webshop and are gonna use session to register products that the customer put in his cart.
The products are going to be registered like this. When clicking the button to buy a products, it sends the product number with it in the link.
The add script i then gonna make a session that has this product number. The first session registered are going to be called 1, and will have the product number in it. When buying a second product the script checks if 1 allready is registered, and if it is, it increases the variable to 2, and so on.
The problem is have to make this work? Increasing the name on tha variable created?
This is what I've done so far since I can't get any further
Code: Select all
<?php
session_start();
$number="1";
while( session_is_registered("$number") )
{
++$number;
}
session_register("number");
?>