1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Chicago, IL USA
    Rep Power
    Ok screw it i'm going to write my own shopping cart ;D , and they call me a newbie. Well i'm guessing I need to start a session and register a unique (crypted) session id for each little visitor to my site sooo...I would do this right?..


    $session = md5(uniqid(rand()));


    Which (as i understand it) register a unique session id for the length of each visitors stay at my site. Well thats great ;D but how would I add a product ID to that session and then call that session ID later on when they visit their shopping cart display. yeah yeah and when they visit their shopping cart page how do I reference those registered product id's against my database and display the adjacent product name's and prices? I would be most grateful if someone could help me.

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Rep Power
    This session stuff is all kind of new.
    This might be an idea to play with. I noticed the manual didn't really have any examples for session_register but mess with this idea:

    have a form in say (shop1.php) or whatever with two variables:

    <form action="<? echo $PHP_SELF; ?> method="GET" ">
    <input type="submit" name="PID1" value="Add to Cart">
    <input type="text" name="SKU93847438" value="1" >

    PID1="Add to Cart" The add to cart button...
    A text field SKU93847438="1" The Product ID

    Some one clicks on it...lets say qty = 1

    You have some code at the beginning of the page.
    if(isset($PID1)) {
    if( session_register('SKU93847438')) {
    // not sure how to pass it maybe in "" or $SKU93847438
    echo "registered<br>";
    else {
    echo "not registered<br>";
    This keeps going....(SIMPLE EXAMPLE)
    At the checkout page:

    use the $HTTP_STATE_VARS which is an associative array and walk through it to extract the info.
    reset ($HTTP_STATE_VARS);
    while (list ($key, $val) = each($HTTP_STATE_VARS)) {echo "$key => $val<br>";}

    You see now the $key can equal the product SKU and $val is the quantity.

    This is kinda rough as you may be getting other info such as session id I don't know but I would play with this approach at first.
    In any event disecting the HTTP_STATE_VARS may be very revealing.

    If you can extract this info the database part is easy

    SELECT name, price, sku, FROM store WHERE sku='$key' etc.

    Get the session stuff working first. Worry about the database later.

    Let me know what you think.


    [This message has been edited by lhallusa (edited July 26, 2000).]
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Rep Power
    Also read this article:

    SR -

    "The fear of the LORD is the beginning of knowledge..."

IMN logo majestic logo threadwatch logo seochat tools logo