SESSION or COOKIE in Virtual Store

0

I'm in a virtual store project, but I have the following dilemma. A certain user accesses the store and places a product in the cart. I'm storing purchases in a DB table as it gets easier to have a drop / cart dropout control, however the user data I'm storing as follows:

if(!isset($_SESSION["SESSIONID"])){
  $dataHora = date("Y-m-d H:i");
  $sessionID = md5($ip.$dataHora);
  $_SESSION["SESSIONID"] = $sessionID;
}else{
  $sessionID = $_SESSION["SESSIONID"];
}

I set the date and time after the IP if the user is accessing from a network, such as work network, so if another user accesses the store through this network, you will not see the purchase of another user from another computer (correct me if I'm wrong).

But what if the user closes the browser without completing the purchase? When you return, the cart will be empty. I thought about storing in Cookie, but what if the browser is not accepting cookies? Is there any other way?

    
asked by anonymous 01.11.2017 / 11:33

2 answers

0

Why do not you use the bank and cookies or session?

Using the bank you are able to know if the user left the cart today at 14:34 or abandoned 456 days ago.

Having control over cart abandonment is very important in order to achieve potential sales regardless of the time the cart is mounted. Leaving such important information in the user's hand is not good, nor practicable, any ctrl-f5 in the browser and you lose all information and consequently data. Dice is money, simple as that.

Create a scan that looks for the data in cookies, if there is no need to spend connection to the database. If it does not exist go there and retrieve this data in the bank.

Always associate the cart with the user id. Create the user table and the cart table containing a foreign key with a userid, so it does not matter if the comrade accesses from the same network or pluto, his cart will always be his.

    
01.11.2017 / 12:57
-2

Cookies do not support both, and session is not good for this. I've tried and I've used HTML5 Localstorage for this sort of thing. This is a kind of local caching API, which holds the data, not just if you close the browser. It keeps data persistently even though chrome is terminated in Task Manager, and then has reset the computer 10 times. Off plates and fonts, etc. Disconnected from the internet (so the session does not roll), and can still support thousands of times more information than would be possible with Cookies. If you've loaded page content for offline browsing, it will also continue to retrieve the data offline. for a budget calculator, for example.

And so on ... HTML5 LOCAL STORAGE.

    
23.10.2018 / 09:51