ID: 20449 Comment by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Feedback Bug Type: Session related Operating System: redhat 7.3 PHP Version: 4.3.0-dev New Comment:
Here is my cart script. The only special thing I do before this is to initiate the session. I always call session_id(an id) before session_start because I can't rely on cookies. The only time I do not call session_id is when the visitor first comes to the site. manage_products() is called on the cart.php page when a user either adds an item or updates an item. Also, cart.php is the only page that manipulates the cart. Every other page simply display cart info. (including the order page) <? function print_cart() { include("cart_display.html"); } function printMiniCart() { include("cart_mini_display.html"); } function print_non_editable_cart() { include("cart_final_display.html"); } function manage_products() { //get the product properties from the get or post variables $prod_id = $_POST["product_id"]; $qty = $_POST["qty"]; if(isset($_POST["options"])) $options = $_POST["options"]; //this is the case when updating else $options = $_POST["color"] . "-" . $_POST["size"]; //blow up the item if it is already in the cart if(isset($_SESSION["cart"][$prod_id])) { //product already in cart $products = explode("+++", $_SESSION["cart"][$prod_id]); $prc = count($products); $product_found = false; for($i=0; $i < $prc; $i++) { //now explode the inner workings of each subproduct $subproduct = explode("|", $products[$i]); //the array of subproduct looks like this //options = $subproduct[0]; //qty = $subproduct[1]; if($subproduct[0] == $options) { //product being added is same as current subproduct. //update the qty $subproduct[1] = $qty; $product_found = true; } //rebuild the subproduct $products[$i] = implode("|", $subproduct); } if(!$product_found) { //product configuration not found in cart. add it to cart $products[] = $options . "|" . $qty; } //rebuild the product string $_SESSION["cart"][$prod_id] = implode("+++", $products); } else { //easy case. Product not in cart //simply add it //build the product identification string $products[] = $options . "|" . $qty; $_SESSION["cart"][$prod_id] = implode("+++", $products); } return true; } ?> Previous Comments: ------------------------------------------------------------------------ [2002-11-17 12:06:13] [EMAIL PROTECTED] ok. This is really frustrating. I wrote a script that simulates a cart. I use fopen once to add something to the cart, and a second time to check the cart. (I use uniqid to create a session id and pass it through the url) The script simulates it 100 times. Then, via a interface and iframes, I have six frames loading the test script. See - http://www.t-shirtking.com/temp/testcart.html This raises the load a little. However, as you will see, it checks out everytime. However, this morning I check my e-mail and find a dozen more messages from the order page that tells me someones cart was empty. Next message, I'm gonna show you my cart. It isn't too complicated. ------------------------------------------------------------------------ [2002-11-17 11:07:55] [EMAIL PROTECTED] I too can't reproduce this bug. Someones when someone uses the Checksheet system the session dies after 15 minutes. I run back and we repeat every step the person did leading up to the session that disappears. Wait 15 minutes, do exactly the same thing, but this time it works. Other times people leave it idle for 2 hours at a time and it disappears, and sometimes it doesn't. But I have my sessions set not to timeout, only after browser closes. I haven't been doing anything special. After the session 'disppears' I log onto the server and look at the session save path directory for the session (in an attempt to recover the data stored in it), and it's no longer there. I'll continue to try and reproduce this bug and if I find anything I'll post here. ------------------------------------------------------------------------ [2002-11-16 20:33:38] [EMAIL PROTECTED] Ok, I can only open or close this. If you'd like, change it to feedback. I will provide more details soon. I'm very anxious to help squash this problem. ------------------------------------------------------------------------ [2002-11-16 20:32:11] [EMAIL PROTECTED] As for an example script...I don't think I could make it short. However, the script is only a shopping cart. I'm not doing anything out of the ordinary. It is a simple array of strings. I try to store the array as a session. Like I said before, I've never been able to break it myself. However, I do see evidence of it breaking. (ie. the e-mail that is sent to me) I guess it should be possible to write a script that continuously tries to add to cart then checkout and see if it would break that way. I will do so and get back to you. In the meantime, I will change the status of this to feedback. ------------------------------------------------------------------------ [2002-11-16 19:55:52] [EMAIL PROTECTED] The php version I'm using at the moment is PHP Version 4.4.0-dev Any other info can be found here. http://www.t-shirtking.com/temp/phpinfo.php ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/20449 -- Edit this bug report at http://bugs.php.net/?id=20449&edit=1