I want to generate a unique key from two strings , string a
and string b
. string a
is already a unique key of length of 8 to 20 chars
, while string b is not unique with same length of 8 to 20 chars
. The target key must be hard to guess, unique and has a fixed length of 10 chars. I have tried some combinations of mad5()
, uniqueid()
and rand()
functions, but target string exceeds the limit of 10 chars
everytime. How can I get key of 10 chars
?
您可以将a和b中的所有字符放入一个数组中,对数组进行随机组合,然后将它们随机从0循环到9
Assuming your target key is stored in the db.
$string1 = 'some_unique_string';
$string2 = 'any_other_string';
do{
$target_string = sub_str(str_shuffle($string1.$string2),0,10);
$sql='select * from table_name where targetKeyColoumn = "'.$$target_string.'"'; //add sql injection prevention
$result = mysqli_query($dbConectionResource, $sql);
$row_cnt = mysqli_num_rows($result);
}while($row_cnt); //if its 0, come out from loop
echo $target_string;
Hope this will help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.