Today i will show you how to generate alphanumeric unique ID using Codeigniter. Some times there is requirement to generate the unique id, But most of the time we are going to write our logic. But Codeigniter Framework Provides Helpers, which simplify our need. One of them is string Helper.
How to use CodeIgniter String Helper:
To use string helper you need to first load it, then use the random_string() function. Generates a random string based on the type and length you specify. Useful for creating passwords or generating random hashes.The first parameter specifies the type of string, the second parameter specifies the length.
The following choices are available: alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
1) alpha: A string with lower and uppercase letters only.
2) alnum: Alpha-numeric string with lower and uppercase characters.
3) numeric: Numeric string.
4) nozero: Numeric string with no zeros.
5) unique: Encrypted with MD5 and uniqid(). Note: The length parameter is not available for this type. Returns a fixed length 32 character string.
6) sha1: An encrypted random number based on do_hash() from the security helper.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.