I have a table “pages”, containing columns “id” and “slug”.
User can create a new Page and I need to automatically create a unique “slug” for it. Here is an example:
pages.cc/X1Af9M
“Slug” is 6 chars alphanumeric string. Every page is unique, so duplicates are not allowed.
What is the best and efficient way of doing it on ServerConnect side? How to generate this profile of string and how to ensure uniqueness without shooting duplicate errors to the user.
Use the Cryptographic function server side, SHA256 or whatever you please, select now as the value, and then select now for the salt. Should insure no collisions.
Thanks, Dave, but what if we have limited number of chars, only 6 or even 5, so URL will look like pages.cc/X1Af9M. SHA produces much longer string, which doesn’t fit the requirement.
I want to do the same thing, but I want the random string to contain a mix of upper case letters, lower case letters and numbers - but not other characters such as $, # etc.
@patrick, what function should I use to create that?
the .md5() function only creates numbers and letters a-f.