There are a number of ways to get random, unique hash values on the web, but much the same:
1, first get the random unique string
2, Carry on MD5 or SHA1 calculate hash value
A project to use the hash value, went online to find, but found that PHP has a function can directly generate a unique string--uniqid (), by using this function, coupled with their own generated random number (to prevent being cracked), more unique and not easy to guess solution. The main issues to consider are as follows:
1. Stochastic efficiency and randomness: Rand and Mt_rand function selection, preferred mt_rand, high efficiency, good randomness;
2, Random times: Choose 5 times, originally Unniqid is the only, plus the random can only enhance security, 5 times enough
3, MD5 or SHA1: can generate a unique hash value, SHA1 occupy resources may be high, but very little, if you consider the database storage of lowercase, you can use MD5 (32-bit length)
<?php
function Get_hash () {
$chars = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@# $%^&* () +-';
$random = $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)]. $chars [Mt_rand (0,73)];/ /random 5 times
$content = Uniqid (). $random; Similar to 5443e09c27bf4ab4ut return
SHA1 ($content);
}
Echo Get_hash ();
? >