You should do the FINAL quantity check when order is placed/submitted, not when added to cart. Think what happens, if somebody adds all products in your system to cart (just for fun).. your eCommerce shop would be sold out :)
So should be like:
- when viewing item available quantity (in stock quantity) use value from database (real, current, available quantity)
- when order is submitted, check that the quantity ordered is available. If not, notify user. If is, make the reduction and save to DB.
There is also lot of well maid, free eCommerce softwares available like: Magento (http://magento.com/)
TIMED SESSIONS:
But if you really want to do the session thing, you can:
- save sessions to database with timestamp
- update timestamp on every page request by user (like "last access")
- periodically delete old session rows and "free" reserved products
Keep in mind that the sessions (reserved products related) should then be quite short (like 30 minutes?).