Summary: Affliate advertising management system
Version: 1.0
Prerequisites: MySQL, MaxMind GeoLite Country
Status: Stable
Maintainer: davidof
Categories: Markup
Download: adit.zipΔ
Discussion: Adit-Talk


Adit arose out of a requirement I had to provide affliate advertising within the pages of my Wiki. Although for affliate advertising you could replace any object, such as a piece of text or image that you want geotargetted by country, related to the page being viewed and rotated.

I have a Wiki that discusses a range of products. In order to offset server/bandwidth costs I have established relationships with several suppliers through their affliate schemes. In general an affliate link consists of a piece of Javascript that links to the product or, more occassional, an image and hypertext link.

Allowing Javascript in Wiki pages in dangerous and including hyperlinks in each product page is labour intensive. For ease of management it would be better to include a code in the GroupFooter or GroupHeader and then fetch any relevant advertising from a database.

Systems to display advertising already exist, for example OpenAds ( However this tool, although powerful is quite complex to use for a wide range of products.


By including a Pmwiki tag somewhere on a page, for example the GroupFooter, Adit can retrieve advertising related to the Page title or Group name. This can be targetted to one or more countries.

(:adit ${Title}, ${Group} :)

of course you can use any keyword pair you like but this is a typical example.


Unpack the zip file. The package consists of two parts. A cookbook recipe and an administration system. Under the cookbook directory you will find

  • adit.php
  • adit/

You will need to add the following line to your local/config.php or local/farmconfig.php file


In order to use the geotargetting features of Adit you will also need to download the MaxMind GeoIP Lite country database from the following website:

This file, called GeoIP.dat should be placed in the cookbook/adit directory. It is a database that maps IP addresses to countries. When someone connects to your wiki Adit uses this database to determine where the user is located in the world.

The second part is an administration tool stored under the adit_admin directory. Copy this to your server's document root (or other location) there are two important files from a setup viewpoint

  • authentication.php
  • globals.php

First authentication controls user access to the administration scrips. The PHP array:

$userDB = array("jo" => "schmoe",
"user" => "secret");

Lets you configure usernames and passwords. You will probably want to change these to your own value(s). There is no real need for more than one user. Multiple users are left open for future user.

Globals configures database access. You will need to set the database name or a table extension if you want to share a database with another application. You will also need to set the username and password you use to access MySQL. The hostname will normally be left at localhost.

# use this if you share a database with another application

You may need to create a user for the adit database. Use the mysql admin tool to do this

e.g. mysql -u root -p
> grant all privileges on adit.* to username@localhost identified by \'password\' WITH GRANT OPTION;@

As a security measure you may wish to rename adit_admin. Note that the globals file is also used by the adit.php cookbook script. If you change the directory name or place it somewhere other than your document root you will need to modify this variable:

include_once($FarmD . "/../adit/globals.php");

Assuming you set up the administration interface under the web server's document root then you will need to run a setup script to create the database tables

You can manage Adit with the following URL:

You will need to give the username and password that you set up in the authentication.php file.

From the administration interface you can add an advert (any HTML code including Javascript) and associate a keyword and countries, update this to add new keywords and delete an advert. If you associate more than one advert with an instance of a keyword and country adit will rotate the displayed code on a round robin basis. You can access statistics showing how many times each ad has been displayed.


I've tested this under a pmwiki 2.* release running on Windows and Gentoo Linux.

Release Notes


See Discussion at Adit-Talk

See Also


User notes -1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.