I've got a lot of really exicting stuff in the works right now, and because I'm anxious to get back into building them (so I can then release them and introduce you to them), I'm going to take the easy way out tonight and just post a PHP version of the Perl key generation script I shared the other day.
It basically does all the same things as the script I mentioned the other (takes an integer and generates a base 36 key), it's just in PHP this time around. I did this version because the front end of the pu.ly site is actually in PHP (and the backend monitoring scripts are in Perl)...so I needed a version of the code in both to keep everything in sync. depending on where/when a record would be inserted into the long tweets table.
Anyway here's the code, enjoy.
<?
function base_conv($num) {
$remainder = $num % 36;
$value = round($num / 36);
$row = array($value, $remainder);
return $row;
}
function generate_key($id) {
$continue = 1;
$slot = 0;
$key = "";
$bits = array();
$control = array();
$remainder = 0;
while ($continue) {
$check = base_conv($id);
$id = $check[0];
$remainder = $check[1];
array_push($bits, $remainder);
if ($id == 0) { $continue = 0; }
}
foreach (range('A','Z') as $value) {
$control[$slot] = "$value";
$slot++;
}
foreach (range(0,9) as $value) {
$control[$slot] = "$value";
$slot++;
}
foreach ($bits as $rev) {
$key .= $control[$rev];
}
return $key;
}
$id = 0;
if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; }
$key = generate_key($id);
// just show the generated key to the user
echo $key;
?>



