And now for the same thing, completely different.

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 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”;
  foreach (range(0,9) as $value) {
    $control[$slot] = “$value”;
  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;

This post has received 43 loves.


This is the personal blog of Kevin Marshall (a.k.a Falicon) where he often digs into side projects he's working on for and other random thoughts he's got on his mind.

Kevin has a day job as CTO of Veritonic and is spending nights & weekends hacking on Share Game Tape. You can also check out some of his open source code on GitHub or connect with him on Twitter @falicon or via email at kevin at

If you have comments, thoughts, or want to respond to something you see here I would encourage you to respond via a post on your own blog (and then let me know about the link via one of the routes mentioned above).