function generateCode($length=6) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHI JKLMNOPRQSTUVWXYZ0123456789";
$code = "";
$clen = strlen($chars) - 1;
while (strlen($code) < $length) {
$code .= $chars[mt_rand(0,$clen)];
}
return $code;
}
$hash = md5(generateCode(10));
$test = $link->query('UPDATE users SET hash = '.$hash.' WHERE ID =1');
setcookie("user_hash", $hash, time() + 3600);