note 25349 added to ref.bc
| From: | pulstar at mail dot com | Date: | Fri, 20 Sep 2002 12:23:07 +0000 |
| Subject: | note 25349 added to ref.bc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37030@lists.php.net to get a copy of this message | ||
A found a little fix to do in my base2dec() function:
The line "if($base<37) $value=strtolower($value);" should be removed if you want to
specify another digits for your base conversions. Change it this way:
if(!$digits) {
$digits=digits($base);
if($base<37) {
$value=strtolower($value);
}
}
Another example using these functions is to generate a key for a session, to name temporary files or
something else:
srand((double) microtime()*1000000);
$id=uniqid(rand(10,999));
$mykey=dec2base(base2dec($id,16),64);
$mykey is a base64 value, which is a good key for passing thru an URL and also is shorter than a MD5
string (it will be allways 11 chars long). If you need something more secure, just scramble the 64
digits in the digits() function.
Well, I hope you enjoy it.
Regards,
Edemilson Lima
--
http://www.php.net/manual/en/ref.bc.php
http://master.php.net/manage/user-notes.php?action=edit+25349
http://master.php.net/manage/user-notes.php?action=delete+25349
http://master.php.net/manage/user-notes.php?action=reject+25349