Unique Identifier for Online Application

Posted on 2007-08-06
Last Modified: 2013-12-24
I am writing an online application where I need to make sure everyone applying gets a unique identifier.  Right now I am using the date and time but I am not comfortable with it.  Right now two people could potentially grab the same number.  

I've read where people recommend ID & Token, but do not know how to implement.  Could someone give me some simple logic for this?  Thanks for helping.  I am using CF7.

What I am using now:
<cfset todaydate = DateFormat(now(), "yyyymmdd")>
<cfset todaytime = TimeFormat(now(), "hhmmss")>
<cfset UniqueNO = '#todaydate##todaytime#'>
Question by:sulzener
    LVL 24

    Accepted Solution

    <cfset UniqueNO = CreateUUID()>
    Guaranteed to be unique!
    LVL 39

    Expert Comment

    You could also just use the database.  When you said "everyone applying..." makes me think there will be a database record of the transaction.

    The primary key of the table would be unique.

    create table applicants (
       applicant_id    int    identity(1,1)   not null


    Author Comment

    Okay, both suggestions work.  dgrafx (#1), answered the question and gdemaria (#2) got me thinking a different direction.   Let me ask a little deeper question.
    I like #1 because I didn't plan to write the record until the very end.
    I like #2 because the number is smaller and I want to use it for a couple things.

    1) The user is attaching two files to the application.  I am using the application no. as part of the file name.
    2)  Also, I'd like to use the number as a tracking number for status lookup capabilities.  #1 creates a huge number.  #2 could be a little small.

    Does this peek any additional reseponses?
    LVL 39

    Assisted Solution


     Don't know how you're doing your application, but the right answer may be "both" methods.

     Once the record is created in the database, I would definately want to be referring to related files and child tables using the primary key of the table and have files and child tables use a foreign key to point to it.

     However, until the user has gone far enough to create the database record, you need to keep track of his information.  This can be done using session variables, form field variables and the session ID that dgrafx mentioned can be a substitute for the primary key prior to its initial insert.

     But I'm curious?   If you're not saving the data into a table yet, why do you need a unique identifier at all ?    What does the unique ID point to exactly?    Typically, if I am collecting information the user is providing, prior to their final  "save" button being pressed, I would do one of two things...

    1)  save the data in the tables anyway, just have a status flag indicating that its "work in progress".   This allows them to return later and finish or take up after a crashed browser.   If the user doesn't finish, you just sweep through and clean up all the records the unfinished status that are X days old.

    2) use client, session, form variables or cookies to maintain the database until its time to save the information into the database.  Which variabel depends on how much data there is and what hoops you have to jump through to get it.

    So, I'm curious how you're doing it and what the session ID will be used for?


    Author Comment

    Phase 1 of the project was to collect the info, email it.  Didn't need to save it.  The unique number was used to basically name the uploaded PDF files, hold them for emailing purposes only.
    In Phase 2, I need to write data to a db, build a tracking portal for internal and external users. The external user will see status only.  The internal user will see everything.  
    I am now working on Phase 2.  I like your suggestion of "work in progess" and even using both methods.  
    LVL 24

    Expert Comment

    hello ...
    After reading the posts since I posted
    it looks like you have 2 different needs.
    for a unique ID in the db I'd definately go with the identity column in db
    but your pdf naming may be a different thing
    can each user get more than one pdf?
    if so - then you can't use the one identity columns value to name several pdfs
    so i guess my opinion would go something like this
    <cfset UniqueNO = CreateUUID()>
    <cfquery ... name="newUser">
    insert into tableusers
    ('#UniqueNo#', '#Email#', '#whatever#')

    Select Needed Columns
    From tableusers
    where UserID = @@Identity <!--- UserID is your identity column --->

    then your code to write your pdf ....
    use your UniqueNo to name it

    then your code to email the pdf to this user
    <cfmail ... query="NewUser">
    Hello ... Here is some spam and a malicious macro from us
    <CFMAILPARAM FILE = "#directorypath_to_your_pdf_dir#\#UniqueNo#.pdf"><!--- add a if fileExists probably --->      

    good luck ...

    Author Comment

    Thank you both for your comments.  They were excellent.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A web service ( is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now