How to generate unique id for non registered users?

884 Views Asked by At

I'm looking for a method to create unique and permanent ID-s for non-registered users in my webshop. I have a working solution if the user is registered:

CREATE TABLE user ( 'user_id' int(11) NOT NULL, 'first_name' varchar(100) NOT NULL, 'last_name' varchar(100) NOT NULL, 'register_date' datetime DEFAULT NULL) 

CREATE TABLE cart ('cart_id' int(11) NOT NULL,'user_id' int(11) NOT NULL, 'item_id' int(11) NOT NULL) 

if($_SERVER['REQUEST_METHOD'] == "POST"){
  if (isset($_POST['submit'])){
       $cart->addToCart($_POST['user_id'], $_POST['item_id']);
      }
  }

Otherwise I have no way to know which cart belongs to whom. I'm trying to use cookies but any kind of advice is welcome.

1

There are 1 best solutions below

0
On

The easiest thing you could do is simply refer to the session id (or equivalent). You mostly just want to identify the guest user, so, any id token would do the job. If your question is "how do i generate unique ids" instead, then look for "uuid".