Search code examples
phpjavascriptuser-interfaceuser-accounts

creating temporary user accounts for a web application in php


I'm building a PHP application where users can design products and then check out to a shopping cart if they want to.

To let the user create a design, I need to assign a user ID and design ID to store it in the database.

There are two types of users who can build designs:

  • registed users. To take care of this, I have no problem.
  • non-registered users. These are guest visitors who might play around with product designs, and then when they hit check out, only then will I ask them to sign up. But in order to store their designs, I do need to have some kind of user ID.

I thought of using a timestamp as this user's ID, but what if two users in different parts of the world create designs at the same time? What's a good strategy for generating IDs for temporary/guest user accounts? I don't just mean temporary in the php session sense, because I want them to be able to access their partially saved designs later on if they visit the site again, just like any other registered user. I will only ask them to sign up before checking out for payment.


Solution

  • A simple approach might be:

    • Use a single user table (for registered users and guests)
    • Assign a "user_type" flag. E.g. registered/guest
    • Use the table primary key or other unique value for both "types" of user
    • When guests check out later on, switch their "user_type".
    • Store other related customer details in a separate table.