|
<?php/* * Created on 2013-3-25 * To change the template for this generated file go to * window-preferences-phpecl Ipse-php-code Templates */function getToken ($len = all, $md 5 = True) {# Seed random number generator # only needed F or PHP versions prior to 4.2 Mt_srand ((double) microtime () * 1000000); # array of characters, adjust as desired $chars = Array (' Q ', ' @ ', ' 8 ', ' y ', '% ', ' ^ ', ' 5 ', ' Z ', ' (', ' G ', ' _ ', ' O ', ' ', ' S ', '-', ' N ', ' < ', ' D ', ' {', '} ', ' [', '] ', ' H ' , '; ', ' W ', '. ', '/', ' | ', ': ', ' 1 ', ' E ', ' L ', ' 4 ', ' & ', ' 6 ', ' 7 ', ' # ', ' 9 ', ' A ', ' a ', ' B ', ' B ', ' ~ ', ' C ', ' d ', ' > ', ' E ', ' 2 ', ' f ', ' P ', ' g ', ') ', '? ', ' H ', ' I ', ' X ', ' U ', ' J ', ' K ', ' r ', ' L ', ' 3 ', ' t ', ' M ', ' n ', ' = ', ' o ', ' + ', ' P ', ' F ', ' Q ', '! ', ' K ', ' R ', ' s ', ' C ', ' m ', ' T ', ' V ', ' j ', ' u ', ' V ', ' w ', ', ', ' X ', ' I ', ' $ ', ' Y ', ' z ', ' * '); # Array Indice friendly number of chars; $numChars = count ($chars)-1; $token = "; # Create Random token at the specified length for ($i = 0; $i < $len; $i + +) $token. = $chars [Mt_rand (0, $numChars)] ; # should token be run through MD5? if ($MD 5) {# Number of 32 char chunks $chunks = Ceil (strlen ($token)/); $MD 5token = "; # Run each chunk through MD5 for ($i = 1; $i <= $chunks; $i + +) $MD 5token. = MD5 (substr ($token, $i * 32-32, 32 )); # Trim The token $token = substr ($md 5token, 0, $len); } return $token;}? >
|