Page 1 of 1

Help with Online KeyGen

Posted: Sat Nov 03, 2012 1:54 am
by illmill
Hi, I'm new to enigma and just doing the trial of the 32 bits program to make sure it works before I buy. I am going to sell software online through paypal and I need them to be able to register a license key after making payment. I'm a complete newb, so please dumb down your directions for me.

I looked here: ... f6ec7d697d and tried using the "post" method as recommended and changed the "" to my actual site, but it's not working. I just get an internal server error. I uploaded the linux keygen to my hostgator reseller account under the cgi-bin directory, so I believe that should work. All I need is for people to enter their name or email (I would prefer email if they can use that as the unique item) and just click generate to get a key. Or a key is automatically emailed to them, but since I don't have the budget for an autoresponder right now, it's better if they can just be redirected to a page that lets them generate a key.

Thanks in advance!

Re: Help with Online KeyGen

Posted: Mon Nov 05, 2012 3:19 pm
by Enigma
Hi illmill,

You are really looking in correct direction.

Just summarize, you need an ability to send automatically the email to user who has bought your software from Paypal.

Initially, as you are correctly noticed, you need to set up the keys generator. You've uploaded keys generator to cgi-bin directory but perhaps, forgot to set execution permissions to this keygen file. By default, Linux sets read/write permissions to the fil, but we have to have execute permissions.
Also, make sure that the keygen file you uploaded is really located in cgi-bin folder. Note, it is not enough just create a folder with the name cgi-bin to allow execution of scripts inside it.

Next, based on the POST example of keygen: ... f6ec7d697d you are making/remaking this script to email a message (for eg, using standard php function mail) with the key to the user who bought the software.
Paypal carries payment details in the POST array. You may extract first and last names, and email address like following:
I hope there is no problems at this stage.

Next stage - integration of keys generator and the php script that sends email to user into Paypal. For this, you have to use IPN (instant payment notification) system of paypal. You have to set the url of the php script to the paypal's IPN so it will call your script each time new order comes.

Re: Help with Online KeyGen

Posted: Tue Nov 06, 2012 3:09 am
by illmill
Okay, thanks for the reply. Sorry about the multiple posts/emails, I was just in a hurry over the weekend to try and get this working.

Yes, I am positive the keygen is in the correct cgi-bin directory. I'm aware of this folder and I uploaded it there via ftp. I will contact my host to ask about the permissions and then post an update here.

Thanks again!

Re: Help with Online KeyGen

Posted: Tue Nov 06, 2012 5:15 am
by illmill
Okay, I'm going to spend some time playing with this to see if I can get it working, but to be honest, I don't really know php so this might be a challenge for me to set up.

I just set up the ipn listener url in my account preferences on paypal, but one thing I'm not sure of: is the URL supposed to be, or is it the url where I upload this script: ... f6ec7d697d (under POST php method).

So I thought I would just post my code here. I named the file paypalipn.php and I uploaded it to and then there is I have absolutely no idea if I'm even close, but here's the paypalipn.php script:

Code: Select all


  if (!function_exists('http_build_query')) {
      function http_build_query($data, $prefix='', $sep='', $key='') {
          $ret = array();
          foreach ((array)$data as $k => $v) {
              if (is_int($k) && $prefix != null) {
                  $k = urlencode($prefix . $k);
              if ((!empty($key)) || ($key === 0))  $k = $key.'['.urlencode($k).']';
              if (is_array($v) || is_object($v)) {
                  array_push($ret, http_build_query($v, '', $sep, $k));
              } else {
                  array_push($ret, $k.'='.urlencode($v));
          if (empty($sep)) $sep = ini_get('arg_separator.output');
          return implode($sep, $ret);
      }// http_build_query

  function do_post_request($url, $data, $optional_headers = null)
   $params = array('http' => array(
                'method' => 'POST',
                'content' => $data
   if ($optional_headers !== null) {
      $params['http']['header'] = $optional_headers;
   $ctx = stream_context_create($params);
   $fp = @fopen($url, 'rb', false, $ctx);
   if (!$fp) {
      throw new Exception("Problem with $url, $php_errormsg");
   $response = @stream_get_contents($fp);
   if ($response === false) {
      throw new Exception("Problem reading data from $url, $php_errormsg");
   return $response;

  function generate_key_post($url, $data) {
    return do_post_request($url, http_build_query($data));
  $data['Action'] = 'GenerateKey';
  $data['KeyMode'] = 512;
  $data['KeyBase'] = 32;
  $data['Hyphens'] = 1;
  $data['EncryptedConstant'] = 2113444489;
  $data['RegName'] = '$_POST['payer_email']';

  $txt = "Hi $_POST['first_name'] $_POST['last_name'], thank you for registering.  Please see your license information below.

  $regkey = generate_key_post('', $data);
  echo('Registration name: $_POST['payer_email']<br/>Registration Key: '.$regkey);";
  // Send email

I just tested it by making a .01usd payment to the account, but didn't get any message at all - nothing from paypal and nothing from my email account that the receiving paypal is under.

Would the code here work for this application?

Re: Help with Online KeyGen

Posted: Tue Nov 06, 2012 8:10 am
by Enigma
In PayPal you should create a BuyNow button. Your customers will be using this button to make a payment.
Only such payments can be processed automatically. Instead, Paypal supports to send/receive variant amount payments, such can't be handled automatically.

Use this url to create a paypal buynow button: ... ype=buynow

At the Step 3 of button creating you will find the field "Add advanced variables", enable it, and add one variable:

Code: Select all

Replace with the url of your php script.

After customer make a payment, using this buy now button, paypal will call your php script where you will be able to generate a key, send email to customer and so on. No need to use additional php scripts, because it makes the procedure too complex.

Let me know if it helps.

Re: Help with Online KeyGen

Posted: Sun Nov 25, 2012 7:42 pm
by bluemans
tried the script,work well in general but i am not able to send the information to the payer mail.
when i use mail("$_POST['payer_email']","Registration",$txt); ,nothing is received but if i change "$_POST['payer_email']" to and email address its works.
Any idea what can cause the problem?

Re: Help with Online KeyGen

Posted: Sun Nov 25, 2012 8:54 pm
by perfectcode

Re: Help with Online KeyGen

Posted: Sun Nov 25, 2012 11:06 pm
by bluemans
thanks a lot!

Re: Help with Online KeyGen

Posted: Mon Nov 26, 2012 12:00 am
by perfectcode

How Create mysql Online KeyGen

Posted: Sat Dec 20, 2014 5:10 am
by amin
I have created a mysql with a table consist of these fields :Reg name,ID,email
But how I can use your sample code( ... 697d#dummy) for this php page that after save valu fields in mysql then use reg name,ID for generat code and send email?
Please help me.