Session_ONEnd on PHP

161 Views Asked by At

I have recently started programming in PHP.

I am building a cart in PHP. I have my products locked in cart when someone adds it to their cart.

I need to unlock those products when the specific user gets logoff or session expires.

How can i call something like session_onend function as in asp/asp.net to unlock/release those locked products?

2

There are 2 best solutions below

2
On BEST ANSWER

Why not consume the product from stock when the order is actually placed. Hold the product until the user fills out the correct info for billing, then reduce inventory when all goes correctly?

4
On

You can write a custom session handler and implement your own garbage collector.
http://www.php.net/manual/en/function.session-set-save-handler.php
But I would advise against such a locking. It will mess your stock. As only a few people will buy their cart load in real.