title: Unique key generation
body: <p>I looking for a way, specifically in PHP that I will be guaranteed to always get a unique key.</p>
  
  <p>I have done the following:</p>
  
  <pre><code>strtolower(substr(crypt(time()), 0, 7));
  </code></pre>
  
  <p>But I have found that once in a while I end up with a duplicate key (rarely, but often enough).</p>
  
  <p>I have also thought of doing:</p>
  
  <pre><code>strtolower(substr(crypt(uniqid(rand(), true)), 0, 7));
  </code></pre>
  
  <p>But according to the PHP website, uniqid() could, if uniqid() is called twice in the same microsecond, it could generate the same key. I'm thinking that the addition of rand() that it rarely would, but still possible.</p>
  
  <p>After the lines mentioned above I am also remove characters such as L and O so it's less confusing for the user. This maybe part of the cause for the duplicates, but still necessary.</p>
  
  <p>One option I have a thought of is creating a website that will generate the key, storing it in a database, ensuring it's completely unique.</p>
  
  <p>Any other thoughts? Are there any websites out there that already do this that have some kind of API or just return the key. I found <a href="http://userident.com" rel="noreferrer">http://userident.com</a> but I'm not sure if the keys will be completely unique.</p>
  
  <p>This needs to run in the background without any user input.</p>