note 101987 added to function.hash
| From: | shimyshack at gmail dot com | Date: | Fri, 21 Jan 2011 18:13:22 +0000 |
| Subject: | note 101987 added to function.hash | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175976@lists.php.net to get a copy of this message | ||
This is a small function I created to generate a unique ID using sha512 encryption.
If $id is NULL, the generated string will be random. If not, the same hash will always be presented,
provided the $salt is the same.
$length is the length of the generated string. If NULL, the default 128 characters is used.
<?php
function gen_unique_id($id = NULL, $salt = NULL, $length = NULL){
$id = ($id == NULL) ? uniqid(hash("sha512",rand()), TRUE) : $id;
$code = hash("sha512", $id.$salt);
return $length == NULL ? $code : substr($code, 0, $length);
}
?>
----
Server IP: 192.41.42.26
Probable Submitter: 63.125.105.130
----
Manual Page -- http://www.php.net/manual/en/function.hash.php
Edit -- https://master.php.net/note/edit/101987
Del: integrated -- https://master.php.net/note/delete/101987/integrated
Del: useless -- https://master.php.net/note/delete/101987/useless
Del: bad code -- https://master.php.net/note/delete/101987/bad+code
Del: spam -- https://master.php.net/note/delete/101987/spam
Del: non-english -- https://master.php.net/note/delete/101987/non-english
Del: in docs -- https://master.php.net/note/delete/101987/in+docs
Del: other reasons-- https://master.php.net/note/delete/101987
Reject -- https://master.php.net/note/reject/101987
Search -- https://master.php.net/manage/user-notes.php