Generating the code is often done from the timestamp . The problem is recording who has what code. This is often done with a database, but if the volumes are not too large, you can use PHP to generate a log file in CSV format. That can be emailed to yourself and down loaded into Excel, or a similar spreadsheet. Then you can sort, query and manipulate the data to your heart's content.
By the way, bear in mind whatever legal requirements apply to holding personal data wherever you are domiciled.