| 
	
 | 
 Posted by Toby Inkster on 01/04/07 10:17 
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
 
[Back to original message] 
 |