-4

How to generate random activation code based on current datetime and username in PHP.

The return value should be like this, i.e:

201605021955Username

function getActivationCode($username){
$activationCode = "";        

 ....

return activationCode;
}
4

2 回答 2

1
function getActivationCode($username){
    $activationCode =date('YmdHi').$username;  
    return activationCode;
}
于 2016-05-02T19:18:57.403 回答
0

您要求的不是随机的,而是:

$string = date('YmdHi') . $username;

另请查看chr函数以从随机数中获取字符(您可以从mt_rand中获取)。

于 2016-05-02T18:29:47.030 回答