Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active May 6, 2017 10:23
Show Gist options
  • Select an option

  • Save james2doyle/d850c7ef32171131303113a205e56796 to your computer and use it in GitHub Desktop.

Select an option

Save james2doyle/d850c7ef32171131303113a205e56796 to your computer and use it in GitHub Desktop.
PHP uniqid function written in pure PHP
<?php
/*
* Use this if you need to recreate `uniqid` in another language
* From: http://php.net/manual/en/function.uniqid.php#95001
*/
// time in microseconds as float
$m = microtime(true);
// show me the results
echo sprintf("%8x%05x\n", floor($m), ($m - floor($m)) * 1000000);
// show me the real call to `uniqid`
echo uniqid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment