title: Generate unique user id in PHP
body: <p>I am developing an app using Laravel which will have a functionality to register user. 
  I want to provide customized unique id to every user (ie: User_id = SM129).
  Userid will have following features:
  1) User id will be auto-generated while registering. 
  2) Auto-generated user id should be Check to a database for its uniqueness.</p>
  
  <p>Currently, I am using following code to generated unique user id based on current date. but there is a chance of duplicity on a username with this. Please help</p>
  
  <pre><code>&lt;?php
  //creates a unique id for user id 
  echo "&lt;br&gt;";
  $day = date('D');
  $month = date('F');
  $year = date('Y');
  $fmonth = substr($month, 0, 1);
  $fyear = substr($year, 2, 2);
  $fday = substr($day, 0, 1);
  $uniq = rand();
  $funiq = substr($uniq, 0, 2);
  $funiq1 = substr($uniq, 0, 1);
  $joint=  'ST'.$fmonth.$fday.$funiq1.$fyear.$funiq ;
  ?&gt;
  
  &lt;input type="text" name="username" value = "&lt;?php echo $joint; ?&gt;"&gt;
  </code></pre>