在我的购物车应用程序中跟踪访问者?

I'm writing a simple shopping cart application and have hit a road block. Currently my shopping cart application associates the shopping cart (in the DB) with the user's id on the site, but I want to allow visitors to add items to the cart as well.

I asked this question a while back on stackoverflow and the one answer I got was "use sessions." However, after reading about sessions, it appears that the session variables are destroyed when the user closes their browser, and on top of that there is a time limit to how long they can last. Additionally, I read that having lots of session variables can "bog down" the server.

So now I'm back to square one. Should I use session variables to keep track of visitors who want to add things to their cart (I would like a visitors cart to remain available to them for a few weeks)? I also thought of using their IP address, but I know that that changes depending on where they are connecting to the internet (if using a laptop).

What do you recommend?

you could also use cookie's which stay for a certain amount(if user allows cookie to be accepted)

Well reading this I could think of one thing, user authentication, in that way wherever they login from you could show items they have browsed with the email addresses they used to login. So basically you have a table with fields user_email,browsed_item_id,timestamp and whenever they browse an item you insert a new row in that table with their email, item id and a timestamp, and in your php code you could check on every visit if any user's timestamp is older than lets say two weeks, and if it is you delete them from the database. Let me know if you need further explanation on this, I've done this couple of times and am familiar with the concept.