Creating a random id or a totally unique ID

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 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?

Daryl Maximo
PHP Programmer - interactivetools.com

i was trying to use it for a download link.

cheers

kenny