Reputation: 57964
When I add something to the cart, the session can be seen immediately afterwards. Once I am redirected to the cart view. The session is gone.
The stranger thing though, if I add something to the cart again, it updates the correct quantity... so obviously its still there.
I do not understand.
I am using CakePHP 1.3. I have a controller called CartsController
with 2 views add
and index
. The add
view expects a parameter of the id to add to cart. So when you go to carts/add/1
it adds product id 1 to the cart ($_SESSION) and then redirects you to the index view (/carts).
If you view the SESSION immediately after its added in the add() function before redirecting to the index view, it has the proper values in it. By the time you reach the index view, the session is empty again (well it has the default Cake Config value but nothing I added).
This would lead you to believe that somewhere in between when it gets added and after it gets redirected the session is being destroyed. But this is not true because if you added the item to the cart again, and view it directly afterwards again, it will show a higher quantity (2 now instead of 1, then 3 then 4 and so forth.) Yet if you view the session somewhere else, its not there.
Does anyone have any idea at all what could be happening here?
I wanted to add, it DOES work as intended the first time you add something to the cart in your browser, but if you leave the site (via external link) with something in your cart and come back, there is nothing in your cart, and nothing can be added again -- thats when the problems outlined above start. This is happening in Chrome, FF, IE.
If you want to see for yourself, steps to reproduce
Your cart is now empty and you can't add anything to cart again
Upvotes: 0
Views: 227
Reputation: 24071
The first time you create a cookie for the HTTP connection, when you come back there is a second cookie for the HTTPS connection, which is only sent back to HTTPS connections. If you would access the page with the same protocoll (both time HTTP or both time HTTPS), you should see your shopping cart.
Passing your session-cookie one time unsecure and one time secure can lead to security problems. I wrote an article about switching between HTTP and HTTPS protocoll:
Switching between HTTP and HTTPS pages with secure session-cookie
but maybe it's easier to connect always with a secure HTTPS connection.
Upvotes: 2
Reputation: 19635
Chances are that you need to call session_start()
(or whatever the CakePHP wrapper function is) on your cart page.
Upvotes: 0