SESSION or COOKIE in Virtual Store

Asked

Viewed 389 times

1

I am in a virtual store project, but I have the following dilemma. A certain user accesses the store and puts a product in the cart. The purchases I am storing in a BD table, because it is easier to have a cart abandonment/withdrawal control, but the user data I am 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, in this way if another user accesses the store through this network, will not see the purchase of the other user from another computer (correct me if I am wrong).

But what if the user closes the browser without finalizing the purchase? Upon returning, 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?

  • I guess that way, just by setting the date and time, you won’t be able to differentiate one machine from another in the same IP. Regarding cookies, I suggest to force the user to accept the use of cookies (check if the browser is accepting. Otherwise, send a message aiming to enable)... or use localStorage...

  • Hello Dvd. Actually differentiates, because the structure is IP + Date + Time + Minute. About localStorage would not have the same functionality as the Cookie and depending on the browser would have a size limit? I confess that I never used the Torage locale.

2 answers

1

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

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

Having control over trolley abandonment is very important to achieving potential sales regardless of the time the trolley was assembled. Leaving this important information in the hands of the user is not good, nor practicable, any Ctrl-F5 in the browser and you lose all information and consequently data. Given is money, simple so.

Create a check that searches the data in cookies, if there is no need to spend connection with the bank. If it doesn’t exist go there and retrieve that data in the database.

Always associate the cart with the user id. Create the user table and the cart table containing a foreign key with user id, so it doesn’t matter if the comrade accesses the same network or Plutão, his cart will always be his.

  • Hello Bsalvo. Exactly. I’m actually following the steps: The customer chooses the product and clicks to view the description. After clicking to buy, it is saved in a table of the BD, where is built his cart and when click to finish, it is taken to the checkout where after logging in/register I update the table of the cart with the ID of the user registration. In the store manager I have a chart where shows the abandonment after and before logging in. Abandonment after checkout, it is easier to send for example that the product is waiting to close purchases or even...

  • ... in the Customer Panel view. My question is when the user does not go through the checkout and purchases are abandoned. How would you make it so that when accessing, the purchases were in the cart, but I ran into the Cookie problem, when the browser has not enabled.

-2

Cookies do not support so much, and Ssion, it is not well for this . I tried it and I’ve been using HTML5 Localstorage for this sort of thing. This is a kind of local cache API, which keeps the data, not just close the browser. It persistently maintains the data even though Chrome is finished in the Task Manager, and then resets the computer 10 times. Turned off the boards and fonts, etc. Disconnected from the internet (so Session doesn’t roll), and can still support thousands of times more information than would be possible with Cookies. If you have uploaded page content to offline browsing, it will also continue to retrieve data offline. for a budget calculator, for example.

And so on and so on... HTML5 LOCAL STORAGE .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.