PHP license key generator

Astraport picture Astraport · Jun 27, 2011 · Viewed 10.8k times · Source

I'm looking for a way to generate license keys by a PHP script and then transfer its to my application (Air, AS3), and in this application to read the data correctly. For example, here is the code:

<?php
  error_reporting(E_ALL);
  function KeyGen(){
     $key = md5(mktime());
     $new_key = '';
     for($i=1; $i <= 25; $i ++ ){
               $new_key .= $key[$i];
               if ( $i%5==0 && $i != 25) $new_key.='-';
     }
  return strtoupper($new_key);
  }
  echo KeyGen();
?>

The generates key about like this: 1AS7-09BD-96A1-CC8D-F106. I want to add some information into key - e-mail user, then pass it to the client (Air app), decrypt the data and dysplay in app.

Is it possible?

Answer

Justin Dearing picture Justin Dearing · Jun 27, 2011

Ok lets break down what you are asking:

You want to:

  1. add some information into key
    Well what information do you want to add? Do you want to make the key longer when you do this? Do you want this information to require a key to decrypt? In the vaugest sense thats quite possible with PHP
  2. e-mail user
    PHP has a mail() function. It pretty much just works.
  3. then pass it to the client (Air app)
    Is the air app invoking this php script via a http request? if so set the content-type and output the key to it.
  4. decrypt the data Back to point 1, possible, but do you want a key or not, and do you care if the format changes. Also, don't you want to decrypt the data in the AS3 app?
  5. display in app. If the AS3 app is going to display the key, or the decrypted data, then it is AS3 where you need to get it to display the data.