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

    Join Date
    Jul 2000
    Location
    Chicago, IL USA
    Posts
    48
    Rep Power
    18
    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_start();

    srand((double)microtime()*1000000);
    $session = md5(uniqid(rand()));

    session_register('session');

    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
    Posts
    43
    Rep Power
    15
    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" >
    </form>

    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.
    <?php
    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.
    <?php
    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.


    ------------------
    lhallusa
    webpatron.com

    [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
    Location
    London
    Posts
    987
    Rep Power
    15
    Also read this article:
    http://www.devshed.com/Server_Side/PHP/Commerce2/

    ------------------
    SR -
    webshiju.com

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

IMN logo majestic logo threadwatch logo seochat tools logo