Skip to main content
Thoughts from David Cornelius

I do a lot of contract programming in a niche market that requires small, custom-written, import/export programs. Some of these can are copied with few modifications for similar customers. Once in a while, there's a common need where the application can be used by several customers. In those instances, I need to implement some form of licensing and accountability but I didn't want anything too elaborate nor do I want to incur ongoing charges for an online API for the one-time pricing structure of the projects I work on. Another caveat was that I needed to tie licensing to the customer's software license with which my import/export program communicated--I could only do that after the software was installed and running and could query its database in order to report that software license back to me.

I came up with a simple solution: a Delphi procedure that runs once when the program starts and calls a PHP script on my webserver with several parameters. The PHP script inserts the values into a local MySQL database from which I can query later with either another PHP script or another Delphi program. All initial licenses are trial licenses, so as soon as the program is run once, it sends the information about the software license back to me.

One of the things I ran into is encoding the parameters into the URL string. I remember using HTMLEncode or something like that awhile back and went looking for it but found what looked like some handy routines in the Indy libraries. However, researching those revealed they wouldn't do what I hoped they would--so eloquently explained on Marc Durdin's blog. So embedded in this procedure is his function, EncodeURIComponent, which makes sure any information I'm sending properly prepares strings with embedded spaces, quotes, and so forth, acceptable for an HTTPS request.

Here's a generic example of this procedure, from my GitHub Gist:

The PHP script that this calls, parses all the parameters into named variables, grabs the IP Address of the caller, and timestamps the information into the database in this simple script:

The structure of the database is self-evident--and completely dependent on the type of information stored.

There may be a better way to do this--and if I wanted to pay for an online service, I'd likely go with InfluxDB--but a couple variations of this have been running on my site for awhile. One of the databases has over 235,000 records in it!

Add new comment

The content of this field is kept private and will not be shown publicly.