note 97949 deleted from function.uniqid by visualmind

From: Date: Tue, 18 May 2010 08:15:25 +0000
Subject: note 97949 deleted from function.uniqid by visualmind
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169342@lists.php.net to get a copy of this message
Note Submitter: james bandit.co nz ---- I wanted a way to return a unique number-based ID to be used (and revealed) on a website. <?php // generate a "unique" number to use as an ID function gen_id($length=16) { $arr = str_split(str_pad(hexdec(uniqid()), $length, str_replace(".", "", $_SERVER['REMOTE_ADDR']))); shuffle($arr); return substr(implode($arr), 0, $length); } ?> It's not perfect by any means, but it does the trick for the small number of IDs I've generated (~30,000) <?php echo gen_id(16); ?> Returns something like: 9222145031239296

« previous php.notes (#169342) next »