Local Mode Tags tutorial

Local Mode invocation tags are intended for advanced users who have a basic understanding of programming in PHP.
A default tag (with the comment block removed) looks like this:

<?php
  // The MAX_PATH below should point to the base of your OpenX installation
  define('MAX_PATH', '/path/to/openx');
  if (@include_once(MAX_PATH . '/www/delivery/alocal.php')) {
    if (!isset($phpAds_context)) {
      $phpAds_context = array();
    }
    // function view_local($what, $zoneid=0, $campaignid=0, $bannerid=0, $target='', $source='', $withtext='', $context='', $charset='')
    $phpAds_raw = view_local('', 4, 0, 0, '', '', '0', $phpAds_context, '');
  }
  echo $phpAds_raw['html'];
?>

But please generate the code from your OpenX installation, choosing the options you want from the invocation tag generation page. The above code will not work on your server because you will have different domain and path settings.
You must first alter the MAX_PATH definition to accurately state where OpenX is located in the server's file system:

  define('MAX_PATH', '/path/to/openx');

The 'view_local' function is the main ad call. The parameters are explained in the comment above the function call. Most likely you will want to leave most of the parameters set to their default values. In this example the zone id is '4' – it will change depending on what zone you were using when generating the local mode tag.
All lines – except the 'echo' line at the end – are intended to be placed before any output from your website. The 'echo' displays the banner on the website. In order to display multiple banners you will want to make multiple calls at the top of your document, and 'echo' the relevant banners where you wish.
To display multiple banners, you can call the zones multiple times in one place and use an array which will store the HTML for all banners. I've added the option ‘Don't show the banner again on the same page’ to the invocation tag, which uses the $phpAds_context array. This will prevent the same banner from being used twice.

<?php
  define('MAX_PATH', '/path/to/openx');
  if (@include_once(MAX_PATH . '/www/delivery/alocal.php')) {
    if (!isset($phpAds_context)) {
      $phpAds_context = array();
    }
    // zone 4
    $phpAds_raw['4a'] = view_local('', 4, 0, 0, '', '', '0', $phpAds_context, '');
    $phpAds_context[] = array('!=' => 'bannerid:'.$phpAds_raw['4a']['bannerid']);
    // zone 5
    $phpAds_raw['5a'] = view_local('', 5, 0, 0, '', '', '0', $phpAds_context, '');
    $phpAds_context[] = array('!=' => 'bannerid:'.$phpAds_raw['5a']['bannerid']);
    // zone 4 again
    $phpAds_raw['4b'] = view_local('', 4, 0, 0, '', '', '0', $phpAds_context, '');
    $phpAds_context[] = array('!=' => 'bannerid:'.$phpAds_raw['4b']['bannerid']);
  }
?>

Notice how an array key like '4a' is added to phpAds_raw. It is used again when telling $phpAds_context what banner id has been used: $phpAds_raw['4a']['bannerid']. So make sure to edit the array key when calling view_local and then again when stating the banner id in $phpAds_context (if you are wanting to block duplicate banners or campaigns. Otherwise, you do not need to use $phpAds_context).
Now, to display the banners simply, place the following command where you want the banners to appear:

<?php
echo $phpAds_raw['4a']['html'];
?>