문제

I want to generate a unique string, but don't want the string to be too long (like max 10-12 chars) but I would like to generate this string off passed in data such as the user id + perhaps the time().

Something like:

$foo = sha1($user_id . time());

..would work if the output string wasn't so long.

It's not for security reasons so doesn't matter if it can be decoded or not, it's just an identifier.

Is there anything I can use - I don't have to pass data into it, I just need to make sure it's unique and only want alphanumeric characters.

도움이 되었습니까?

해결책

For an easy solution based in your idea, you could use the hex representation of your values:

$foo = sprintf ("%x%x", $user_id, time());

or

$foo = dechex($user_id) . dechex(time());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top