How to useuniqid() function in PHP
The uniqid( ) function in PHP is an inbuilt function which is used to generate a unique ID based on the current time in microseconds (micro time). By default, it returns a 13 character long unique string.
Example:
<?php
$result = uniqid();
echo $result;
?>
Output
6317481fbacc1
NOTE: All the above approaches are built on rand() and uniqid() functions. These functions are not cryptographically secure random generators. So it is advised that if the degree of randomness affect the security of an application, these methods should be avoided.
Generating Random String Using PHP
Generate a random, unique, alpha-numeric string using PHP. Examples:
EA070
aBX32gTf
Table of Content
- Brute Force
- Using Hashing Functions
- Using uniqid() function
- Using random_bytes() function. (Cryptographically Secure)
- Using random_int() in a Custom Function