title: Which is the most secure method of creating a cryptographically unique token in PHP
body: <p>I have this working I would just like some advice on the most secure option of creating a token (for an API) and would either of them have any issues going forward?</p>
  
  <p>Option A:</p>
  
  <pre><code>$token = bin2hex(openssl_random_pseudo_bytes(16));
  </code></pre>
  
  <p>or Option B:</p>
  
  <pre><code>// $username - unique username for this user
  $token = hash('sha512', sha1($username.time().rand(1000, 9999)));
  </code></pre>