Commercial Break (A phpAds Primer) - Room With A View()
(Page 5 of 9 )
Remember how, a couple of pages back, you wondered what the AdViews, AdClicks and AdDays parameters were for in the client administration screen, and I rudely told you to shut up and sit down? Well, now that you know how banners work, it's safe to revisit those three mysterious parameters, and see where they fit in.
The AdViews parameter lets you specify the number of times the client's banners should be displayed to site visitors, while the AdClicks parameter lets you specify the number of banner clicks purchased by the client. The AdDays parameter lets you specify a duration for which the client's banners are valid; this value is used to calculate the expiry date for the customer's banners.
It should be noted, however, that the values above are largely toothless tigers, since phpAds does not automatically terminate display of the customer's banners once any of the values are exceeded. Rather, it merely uses them to warn the customer when his account is about to expire. This behaviour is somewhat strange - ideally, once the customer's account has expired, banner display should also stop - and you might want to correct it by modifying the source code of the application.
Anyway, back to business. Adding phpAds to your Web site is a pretty painless process - it merely involves adding a couple of hooks to your Web pages. In order to better understand it, consider the following simple HTML page:
<html>
<head>
<basefont face="Arial">
</head>
<body>
<table height="100%" width="100%" border="0" cellspacing="5"
cellpadding="5"> <tr>
<td align="center">Ad goes here</td>
</tr>
<tr>
<td height="100%" width="100%" valign="top" bgcolor="silver"
align="left">
<h2>Sample page</h2>
<center>
Content here
<p>
Content here
<p>
Content here
<p>
</center>
</td>
</tr>
</table>
</body>
</html>
Here's what it looks like:

Now, let's suppose I want to add a banner to this page. I've got my phpAds all set up with client information and a bunch of banners. The first step, then, is to include some required files at the top of my HTML (now PHP) page.
<?
require("phpAds/config.inc.php3");
require("phpAds/view.inc.php3");
require("phpAds/acl.inc.php3");
?>
Next, I need to use the phpAds-supplied view() function to
actually display a banner. This function takes five arguments, of which only the first one is compulsory. This first argument may be a banner ID, a keyword or image dimensions - phpAds will display a banner matching the argument specified.
In order to illustrate this, consider the following updated HTML page:
<?
require("phpAds/config.inc.php3");
require("phpAds/view.inc.php3");
require("phpAds/acl.inc.php3");
?>
<html>
<head>
<basefont face="Arial">
</head>
<body>
<table height="100%" width="100%" border="0" cellspacing="5"
cellpadding="5"> <tr>
<td align="center"><? view(15); ?></td>
</tr>
<tr>
<td height="100%" width="100%" valign="top" bgcolor="silver"
align="left">
<h2>Sample page</h2>
<center>
Content here
<p>
Content here
<p>
Content here
<p>
</center>
</td>
</tr>
</table>
</body>
</html>
When this page is accessed through a Web browser, phpAds will
wake up, read the argument passed to view() - a banner ID - and display the banner corresponding to that ID.
If you look at the source of this page in your browser, you'll see that the call to
<? view(15); ?>
has been magically converted into a clickable hyperlink
<a href="http://www.melonfire.com/phpAds/click.php3?bannerID=15"><img
src="http://www.melonfire.com/phpAds/viewbanner.php3?bannerID=15"
width=100 height=100 border=0></a>
Downside? You don't want this, because it means you'll always
be stuck with the same banner on your page. And while loyalty is a nice concept, you're interested in satisfying as many customers as possible so that you can buy your own island and retire. Which is why you might prefer this:
<tr>
<td align="center"><? view("kids"); ?></td>
</tr>
In this case, phpAds will display a random banner containing
the keyword "kids".
You can even display a banner on the basis of its dimensions. Consider the following example, which displays a random banner of size 600x60:
<tr>
<td align="center"><? view("600x60"); ?></td>
</tr>
If images aren't your thing, you can display an HTML banner
by specifying the keyword "html" as an argument to view().
<tr>
<td align="center"><? view("html"); ?></td>
</tr>
There's a lot more that you can do with view() - and most of
it is explained on the next page. Keep reading.
Next: The Advanced Course >>
More PHP Articles
More By Harish Kamath, (c) Melonfire