简体   繁体   中英

How to generate unique id for non registered users?

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.

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM