• Installing PHP-KeyCodes for selling license key codes

  • PHP-KeyCodes

    Installation Requirements

    • PHP 7 and 8
    • Apache web server
    • An SSL certificate on your web server to use https for communications with PayPal
    • MySQL database version 3.23 or higher
    • Linux, FreeBSD or Windows operating system on the web server
    • A Paypal Business or Premier account - sign up here.
    • Email functionality on the web server so that the PHP scripts can send out emails to customers.
    • If you are looking for a suitable host for you site, I would recommend the basic web hosting plan from siteground which has all the required features for this application.
  • PHP-KeyCodes

    Unzipping the files

    The files are supplied in .zip format. After unzipping the files you will have a folder called 'phpkeycodes' containing a number of files and folders. It is usual to copy the whole folder on to your web server in which case the site will be located at http://www.yoursitename.com/phpkeycodes/.

    If you do create a folder called 'phpkeycodes' on your web server, remember to use lower case as Linux is case sensitive.

    Site structure

    Here is a quick summary of the 'phpkeycodes' folders:

     /admin - code to administer the application

     /classes - object classes used in the application

     /functions - miscellaneous functions

     /images - graphics

     /ipn - PayPal ipn scripts

     /ipn_sandbox - PayPal ipn sandbox testing scripts

     /ipncommon - common ipn functions

  • PHP-KeyCodes

    Creating a Database

    Create a mySQL database with cpanel tutorial (old style) Click here for a tutorial

    Create a mySQL database with cpanel tutorial (new style) Click here for a tutorial

    Create a mySQL database with GoDaddy hosting tutorial Click here for a tutorial

  • PHP-KeyCodes

    Create a database

    Create a new empty database with an appropriate name (e.g. sales or products).

    If you are using a hosting company, then you will probably be given a control panel to access your databases system. For mySQL this is usually phpMyAdmin which allows you to administer the database via a web browser.

    Quite often hosting companies will prefix the name of the database with your login name. So when you enter key codes, it becomes paul_keycodes for example.

    You can install into an existing database if you wish. The table names are all prefixed by ipn_. First check that there are no other tables in your database that start with ipn_ to make sure that there are no name clashes.

  • PHP-KeyCodes

    Create a user for the database

    Create a user (e.g. keycodesuser) that has access to that database and that database only.

    If you are using a hosting company, there will probably be an administration page which will allow you to create database users, define their permissions and add the user to your database.

    Quite often hosting companies will prefix the user name with your login name. So when you enter phpkeycodeuser, it becomes paul_phpkeycodeuser for example.

    In the first instance, you need to make sure that the user has permissions which include CREATE privileges because the first script that you run will be creating tables in the database. Normally you will select the All Privileges option for this.

  • PHP-KeyCodes

    Run the install.php page

    The install.php page should be accessible at :


    When you display this in your web browser, it will ask for host name, database name, username and password.

    PHP-KeyCodes Installation screen - Script for License Key Codes

    The above image shows the default display.

    The host name will usually be localhost, the database name will be whatever you have already created, usually phpkeycodes

    Click on 'Create' and the script will display a list, which should all be green to indicate success. Any failures will be indicated in red.

    If all are green, then all tables have been created.

  • PHP-KeyCodes

    Edit config.php

    The config.php file contains the database connection username / password for the application.

    Edit the config.php file with a text editor such as Notepad. Do not put any spaces, blank lines or other text after the last ?> symbol or before the first <?php symbol.

    You need to enter:

    • database host name (usually localhost, but see your hosting documentation for this)
    • database name
    • database username
    • database password

    Note that the database name, and database username may have been given a prefix by the host system.

  • PHP-KeyCodes

    Modifications to your PayPal account

    If you have not enabled IPN in your PayPal account, you do need to enable it so that your PayPal account sends back the IPN.

    • Log into your PayPal account and click on the cog icon in the top right hand side of the menu.
    • Click on 'Seller Tools' in the sub menu.
    • Under 'Instant payment notifications', click on 'Update'.
    • Enable the IPN.

    In the url box, enter the confirm.php url which will be http://www.yoursitename.com/installation_folder/ipn/confirm.php. This url is not actually needed because the PHP script sends the url to PayPal anyway.

    If the url box is already being used by another application, you do not have to change it because the PHP script sends the url to PayPal anyway.

  • PHP-KeyCodes

    Set up

    The application should now be working correctly and you can go to the admin pages using :


    The default login is
    user: admin@somewhere.com
    password : password

    You should change your password and user name as soon as possible via the 'change password' page.

  • PHP-KeyCodes

    Display the buy now buttons

    Examples of how to display your products onto a web page are explained on the following associated pages :

    Buttons added by hand to your web pages

  • PHP-KeyCodes

    Post Installation

    At this point the application should be working so that you can log on to the admin section and click through the displays.

    The following is not meant to replace the full explanation of each administration display, but provides a quick test to check operation.

  • PHP-KeyCodes

    Basic set up

    Log on to the administration displays of PHPKeyCodes and click on Global setup link in the main menu which will take you to the global set up page.

    The only required entries are :

    • your admin email address - this will be the email 'from' address and so should have the same domain as the site that the application is installed on, or otherwise customers may not receive their emails
    • the installation url where phpkeycodes has been installed - for example http://www.yourservername.com/phpkeycodes/

    Note that you do not have to make any changes to you PayPal account to identify the PayPal IPN or anything like that.


    If you are using PayPal, then you need to enter :

    • your PayPal email address - this should be the primary email address you have registered with PayPal
  • PHP-KeyCodes

    Create a product

    Log on to the administration displays of PHPKeyCodes and click on Global setup

    To be able to test if the system is working, you need to create a new product :

    Click on Product list in the main menu which will allow you to create a new product item.

    Click on the Create button and fill in the required fields.

    At this stage enter any test data into the fields.

    In the key codes field, enter a series of pin codes. Enter say 10 lines.

    Click on Save when finished.

  • PHP-KeyCodes

    Perform a local test

    Click on PayPal Testing in the main menu. This will display a list of products that you have created. To test a particular product, click on Select Local PayPal Test.

    This will display a page with a number of entries. You only need to enter the payer email address as all other fields have been filled in by the system.

    Enter a valid email address.

    Press Perform Test and you should see a page which displays the details of the sent emails. If you go to your email accounts you should see these emails.

    Go back to the product item and check that the top key code has gone from the key code list.

    If this has been successful, it indicates that the application, emails and database are all working correctly. It does not check the operation with PayPal as this is a local test which by passes PayPal. To fully test the system with PayPal perform the test below.

  • PHP-KeyCodes

    Perform a full PayPal test

    The best method to do a test with PayPal is with a second PayPal account. You cannot make a purchase from your own account.

    Create a product with a small value of say $0.01

    In the list of products in the admin page you will see a link called 'buttons'. Click on this link and you will see a button for the product you have created.

    Click on the button and it should take you to PayPal where you can purchase the item using your second PayPal account.

    You should receive an email from PayPal detailing the payment and an email from PHPKeyCodes with your key code.

    If you go back to the admin pages you should see that the key code has been removed from the list.

    Correct completion of this test indicates the system is working correctly with your PayPal account.