| 
	
 | 
 Posted by Tom on 01/04/07 13:21 
Hey 
 
Wow! 
 
Nice, exactly what I needed. 
 
Thanks a lot! 
 
Tom 
 
 
"Toby Inkster" <usenet200701@tobyinkster.co.uk> wrote in message  
news:2r0v64-o98.ln1@ophelia.g5n.co.uk... 
> Tom wrote: 
> 
>> 10 => DFG56JKG4 => 10 
>> 
>> How do I accomplish that? 
> 
> How about this... 
> 
> define('MYSECRET','Some unguessable string'); 
> 
> function int2code ($i) 
> { 
> $md5 = strtoupper(md5(MYSECRET.$i)); 
> $mdStart = substr($md5,  0, 4); 
> $mdEnd   = substr($md5, 28, 4); 
> return $mdStart.$i.$mdEnd; 
> } 
> 
> function code2int ($code) 
> { 
> preg_match('/^([A-F0-9]{4})([0-9]+)([A-F0-9]{4})$/', $code, $matches); 
> $i = $matches[2]; 
> 
> $md5 = strtoupper(md5(MYSECRET.$i)); 
> $mdStart = substr($md5,  0, 4); 
> $mdEnd   = substr($md5, 28, 4); 
> if ($mdStart.$i.$mdEnd==$code) 
> return $i; 
> 
> return FALSE; // Invalid code! 
> } 
> 
> --  
> Toby A Inkster BSc (Hons) ARCS 
> Contact Me  ~ http://tobyinkster.co.uk/contact 
>
 
  
Navigation:
[Reply to this message] 
 |