Creating a random id or a totally unique ID
5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: December 21, 2015 (RSS)
By Twocans - November 5, 2015
Hello,
How would I best create a unique ID with the membership signup, is there something I can call and place it on my page to show a unique id aka sha like
a7sdf7dfgtb7sdfsd798s7df9sdf
I have tried calling this on the signup page but lol it didnt work.
<?php echo htmlencode(@$_REQUEST['randomSaveId']); ?>
regards
kenny
By Daryl - November 10, 2015
Hi Kenny,
You can use uniqid("yourprefix_") to generate a unique ID.
And you might want to check the generated ID against your records, if it already exists, generate a new one.
It may not be the best way for your purpose, but it's the easiest.
Do you need it to be human-readable or extremely hard to guess or it doesn't matter as long as it is unique?
Cheers,
PHP Programmer - interactivetools.com
By Twocans - November 12, 2015 - edited: November 12, 2015
Daryl Thank You,
I just wanted something totally unique.
<?php echo md5(uniqid(rand(), true)); ?>
the above works but i am not sure how unique it would be, I was just wondering did the cms have something I could call which would be long and unique
regards
kenny
By Daryl - November 12, 2015
Hi Kenny,
I usually use websiteMembership plugin's wsm_generatePassword() function for generating random strings, which is basically:
substr(md5(uniqid(mt_rand(), true)), 15)
I think it will generate an id unique enough for usual unique id use. And to double check if it's unique, I checked it against the records, generate a new one if a match is found.
You can also increase the uniqueness of the string by adding timestamp:
$uniqueId = time() . substr(md5(uniqid(mt_rand(), true)), 15);
Just curious, where are you going to use the unique ID?
PHP Programmer - interactivetools.com