Hi,

I've started developing a shopping cart and was just testing and found
that I get strange results when Zone Alarm's Cookie Control is set to
anything other than "Off".

If anything, I would expect the shopping cart to forget its contents
between pages but instead I am getting weird results.


(I have many other files/classes being called from this test.php file)

test.php
--------
<html>
<head>

<?php
// I include all my necessary files/functions (none of which require the
session
// to already be started)

session_start();
if ( !isset( $_SESSION[ 'cart' ] ) ) {
        $_SESSION[ 'cart' ] = new Cart();
}

?>

</head>
<body>


<?php
$f_id = isset( $_POST[ 'f_id' ] ) ? $_POST[ 'f_id' ] : 1;
$f_price = isset( $_POST[ 'f_price' ] ) ? $_POST[ 'f_price' ] : 0;
$f_qty = isset( $_POST[ 'f_qty' ] ) ? $_POST[ 'f_qty' ] : 1;
$f_desc = isset( $_POST[ 'f_desc' ] ) ? $_POST[ 'f_desc' ] : '';

// Form action
$f_act = isset( $_POST[ 'f_act' ] ) ? $_POST[ 'f_act' ] : '';

if ( $f_act == 'add' ) {
        $_SESSION[ 'cart' ] -> add_item( $f_id, $f_qty, $f_desc, $f_price, '' );
} elseif ( $f_act == 'remove' ) {
        $_SESSION[ 'cart' ] -> remove_item( $f_id );
} elseif ( $f_act == 'update' ) {
        $_SESSION[ 'cart' ] -> update_item( $f_id, $f_qty, $f_price, false );
} else {
        echo '<pre>';
        print_r ($_SESSION);
        echo '</pre>';
}

?>


<form action="<?php echo $_SERVER[ 'PHP_SELF' ]; ?>" method="post">
        <input type="hidden" name="f_price" value="10.00" />
        Product = CD
        <input type="hidden" name="f_desc" value="CD" />
        <input type="hidden" name="f_id" value="1" />
        Qty:<input type="text" name="f_qty" size="3" maxlength="4" value="1" />
        <input type="submit" name="f_act" value="add" class="button" />
        <input type="submit" name="f_act" value="remove" class="button" />
        <input type="submit" name="f_act" value="update" class="button" />
</form>


<?php
        echo '<pre>';
        print_r ($_SESSION);
        echo '</pre>';

?>
</body>
</html>

--------------------------------------------------------------

This script obviously calls itself (not sure if that is part of the
problem?)


Scenario (with ZA cookie control set to Medium)
-----------------------------------------------

Leave the quantity set to 1 and click add, the session then shows that there
is one item in the cart.

Click add again and there are 3 items in the cart.
Click again and there are 5 items.

If I now change the quantity to say 10, there will be 16 items (the 5 that
were
there a minute ago plus the 10 plus what appears to be the value that
quantity
was previously set to i.e. 1.

Thus if I then go and set the quantity to 5, it will take the previous value
(10)
plus the new value (5) and add it to the cart (16), giving 31.


Turning ZA OFF and all works as expected.

Since my cart is a serious of objects/arrays, I changed the following to try
and track
down the problem.

Changed:
--------
session_start();
if ( !isset( $_SESSION[ 'cart' ] ) ) {
        $_SESSION[ 'cart' ] = new Cart();
}

?>


To:
---
session_start();
if ( !isset( $_SESSION[ 'cart' ] ) ) {
        $_SESSION[ 'cart' ] = new Cart();
        $_SESSION[ 'count' ] = 0;
}

$_SESSION[ 'count' ]++;
echo $_SESSION[ 'count' ];
?>


The count variable was also going up in the same fashion as the cart items
which makes me think that the page itself is being called several times
before
being displayed.


I'm tearing my hair out here and I can't leave it as is and the cart has to
go into production and I can't have people buying 31 items when they wanted
3 :)

Anyone any suggestions at all.


Regards,

Neil Stiron


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to