background image

 

* The reverse is done because it makes it slightly more cryptic,

 

* but it also makes it easier to spread lots of IDs in different

 

* directories on your filesystem. Example:

 

* $part1 = substr($alpha_id,0,1);

 

* $part2 = substr($alpha_id,1,1);

 

* $part3 = substr($alpha_id,2,strlen($alpha_id));

 

* $destindir = "/".$part1."/".$part2."/".$part3;

 

* // by reversing, directories are more evenly spread out. The

 

* // first 26 directories already occupy 26 main levels

 

*职业 职业发展

 

* more info on limitation:

 

* but I haven't really dugg into this. If you have more info on those

 

* matters feel free to leave a comment.

 

*

 

* @author  Kevin van Zonneveld <kevin@vanzonneveld.net>

 

* @author  Simon Franz

 

* @author  Deadfish

 

*

 

* @param mixed   $in    String or long input to translate

 

* @param boolean $to_num  Reverses translation when true

 

* @param mixed   $pad_up  Number or boolean padds the result up to a specified length

 

* @param string  $passKey Supplying a password makes it harder to calculate the original ID

 

*

 

* @return mixed string or long

 

*/

function

 alphaID(

$in

$to_num

 = false, 

$pad_up

 = false, 

$passKey

 = null)

{

  

$index

 = 

"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  

if

 (

$passKey

 !== null) {

    

// Although this function's purpose is to just make the

    

// ID short - and not so much secure,

    

// with this patch by Simon Franz ()

    

// you can optionally supply a password to make it harder

    

// to calculate the corresponding numeric ID

 

    

for

 (

$n

 = 0; 

$n

<

strlen

(

$index

); 

$n

++) {

      

$i

[] = 

substr

$index

,

$n

 ,1);

    

}

 

    

$passhash

 = hash('sha256',

$passKey

);

    

$passhash

 = (

strlen

(

$passhash

) < 

strlen

(

$index

))

      

? hash('sha512',

$passKey

)

      

$passhash

;