Home arrow PHP arrow Page 6 - Commercial Break (A phpAds Primer)

The Advanced Course - PHP

Wanna make some money from your Web site? The simplest way tostart is by opening it up to advertisers - and if you decide to go thatroute, you're going to need a capable banner management program to helpyou keep track of customers, banners and clicks. Lukily, we've got justthe thing - say hello to phpAds.

TABLE OF CONTENTS:
  1. Commercial Break (A phpAds Primer)
  2. Getting Started
  3. The Toy Store
  4. Different Strokes
  5. Room With A View()
  6. The Advanced Course
  7. Access Denied
  8. The Number Game
  9. Endgame
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 2
July 30, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
You'll remember that only the first argument to view() is compulsory - all the rest are optional. However, these optional arguments can come in pretty handy at times. For example, let's suppose you have a client who's paid you a premium to display only his banners on a particular page of your site. However, the view() function, by itself, displays a random customer's banner each time it is invoked. Not a Good Thing at all.

You can modify this default behaviour of the view() function by passing it a second argument, a client ID. This forces view() to only displays banners belonging to that client when it is invoked, and can come in handy when you want to mark certain pages as exclusive to particular customers. Here's an example, which only displays banners belonging to customer ID 21.

<? view("teenagers", 21); ?>
By default, clicked banners open up in the same browser window - which may not be acceptable to you. You can use the third argument to view() to specify a different target for clicks - as in the following example, which launches the target of each banner in the window named "ad".

<? view("teenagers", 21, "ad"); ?>
The fourth argument to view() is a Boolean, which allows you to hide or show the optional text under the banner. By default, the text display is turned off; you can turn it on with something like this.

<? view("teenagers", 21, "ad", true); ?>
The last optional argument to view() is probably also the most complex - it is used as a filter to restrict the banners displayed. It consists of an array, which in turn consists of one or more associative arrays. Each of these associative arrays contains a key - which must be either the equality operator == or the inequality operator != - and a value, which must be a banner ID. This series of nested arrays is used by phpAds to provide very focused control over which banners can appear on which pages.

Consider the following example, which displays two banners on the same page. Since the selection of banners is random, it's possible that the same banner could be repeated in both places. You can avoid this by creative use of the banner filter, as in the example below.

<? 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"><? $id = view("studio"); ?></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> <tr> <td align="center"><? view("studio", NULL, NULL, true, array(array("!=" => $id))); ?></td> </tr> </table> </body> </html>
In this case, the first call to view() returns a banner whose ID is stored in the PHP variable $id. The second call to view() then uses this $id variable, in combination with an inequality operator, to ensure that the same banner does not get repeated.

You can reverse things so that the same banner appears at both the top and bottom of the page, by using the equality operator instead of the inequality operator in the example above. Try it yourself and see.

 
 
>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: