phpAdsNew  Home 

 

 

 

  4.1 How to display banners  

 

Once you have added banners to your system you also want to display them on your website. The first decision to make is to choose between local mode or remote invocation. The differences are outlined below. To use local mode your webserver needs to support PHP. Remote invocation can also be used on webserver which don't support PHP.

To display a banner on your site you need to place a small piece of PHP or HTML code, caller banner or invocation code, on the pages of your website. The basic examples are listed below, but you can also use the banner code generator in the admin interface of phpAdsNew. Each type of invocation can be configured using a specific number of parameters, which are describe in the next couple of sections.

 
  
  4.1.1 Local Mode 

 


This is the traditional style of a including a banner within a PHP-powered website. On every page you want to have a banner, you have to include phpadsnew.inc.php. If you want to display more than one banner on a specific page you only need to include this file the first time. This file is in your phpAdsNew installation-directory. Banners are displayed using the view() function. This function has the following syntax:

int view (mixed what [, int clientid [, string target
          [, string source[, bool withtext = 0[, array context]]]]);

The view() function does not work well in template-based websites (for example phplib or fasttemplate), because the view() function prints the banner directly to the screen. The banner would appear before the rest of the page is printed. In order to make phpAdsNew work in template based websites there is a function that returns both the html code ($array["html"]) and the banner id ($array["bannerID"]) in an array. The function does not print anything to the screen.

array view_raw (mixed what [, int clientid [, string target
                [, string source[, bool withtext = 0[, array context]]]]);


An example:

<?
  require("/usr/local/etc/phpAds/phpadsnew.inc.php");
?>

<html>
  <head>
    <title>phpAdsNew demo</title>
  </head>
  <body>
    <?
      view("468x60");
    ?>
  </body>
</html>

 

 
  
  4.1.2 Remote Invocation 

 


It is also possible to use phpAdsNew on sites that lack PHP-support. Random or predefined banners can be shown using a standard <img>-construct. Just like in Local Mode, you can use the "what" argument to select the banner. In addition to the what parameter you can configure adview.php with the following parameters: clientID and source.

<a href="adclick.php"><img src="adview.php"></a>

Remote Invocation does have some limitation, for example: cookies must be enabled and HTML banners won't work at all. It is recommended to use Remote Invocation as a fallback instead of the main method of displaying banners.

Important: To use multiple banners on a single page, you must assign a unique name to each invocation code. It doesn't matter what you use as the unique name as long as you are sure the name is not used by any other invocation code on the same page. You must assign it to the "n" parameter for both "adclick.php" and "adview.php". You need to make sure the same value is assigned to both files. This way phpAdsNew can keep track of which AdView belongs with which AdClick.

<a href="adclick.php?n=ban1"><img src="adview.php?what=468x60&n=ban1"></a>
  Show a randomly selected banner of the size 468x60.

<a href="adclick.php?n=top"><img src="adview.php?what=main&n=top"></a>
  Show a randomly selected banner from the "main" group with the name "top".

<a href="adclick.php?n=left"><img src="adview.php?what=468x60&n=left"></a>
  Show a randomly selected banner of the size 468x60 with the name "left".

 

 
  
  4.1.3 Remote Invocation for iframes 

 


It is also possible to use phpAdsNew in combination with iframes. An iframe is an independent html file inside your main page. There is a big advantage in using Remote Invocation for iframes, because the banner is resides in an independent html file your main page will keep loading and the layout will not wait for the banner even when the banner is not completely finished loading.

Unfortunately, not all browsers support iframes. However there is a way to use iframes and be certain the banner will be displayed in all browsers. This method is described in the section 'Combined Remote Invocation'.

<iframe src='adframe.php?what=468x60' framespacing='0' frameborder='no'></iframe>

The following parameters can be used in combination with Remote Invocation for iframes: what, clientID, target, source, withText and refresh.

 

 
  
  4.1.4 Remote Invocation with JavaScript 

 


Just like iframes, this technique allows you to use HTML banners remotely. Just like in Local Mode, you can use the "what" argument to select the banner. All you need to do is insert this code:

<script language="JavaScript" src="adjs.php"></script>

You can also add parameters to adjs.php. The following parameters are compatible with Remote Invocation with JavaScript: what, clientID, target, source and withText.

<script language="JavaScript" src="adjs.php?what=main&target=_blank">
</script>
  This would show a banner from the main group and, when clicked,
  a new window would be opened.

 

 
  
  4.1.5 Combining the different types of Remote Invocation 

 


The preferred type of Remote Invocation is the iframes variant. However iframes aren't supported on all browsers, so it may be needed to use a combination of different types of Remote invocation.

<iframe src='adframe.php?what=468x60' framespacing='0' frameborder='no'>
<script language='JavaScript" src="adjs.php?what=468x60'></script>
<noscript><a href='adclick.php'><img src='adview.php?what=468x60'></a></noscript>
</iframe>

The example above will try to use iframes when possible, but if the browser doesn't support iframes it will try to use remote invocation with JavaScript If the browser doesn't support JavaScript or JavaScript is turned off, the browser will use normal remote invocation. If you decide to use such a construction please note you need to specify the parameters for each type of invocation (adframe.php, adjs.php and adview.php).

Warning: Combined Remote Invocation doesn't seem to be compatible with IE6. We are working on a solution of this problem.