note 61662 added to function.rand
| From: | jon at zerogen dot co dot uk | Date: | Wed, 08 Feb 2006 17:50:52 +0000 |
| Subject: | note 61662 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103324@lists.php.net to get a copy of this message | ||
I know the code is a bit crappy but i use this to generate a random code
$acceptedChars = 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789';
$max = strlen($acceptedChars)-1;
$code1 = null;
for($i=0; $i < 6; $i++) {
$code1 .= $acceptedChars{mt_rand(0, $max)};
}
$ttcode1 = $code1 . $email . time();
$ttcode2 = md5($ttcode1);
$ttcode = substr($ttcode2,0,10);
it grabs a random 6 digit code, then adds the email address and the time stamp, md5 all of that then
i've got a unique code
----
Server IP: 85.116.0.130
Probable Submitter: 84.233.227.59 (proxied: 10.250.248.122)
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61662
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61662&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61662&report=yes
Search -- http://master.php.net/manage/user-notes.php