PHP
  Home arrow PHP arrow Page 6 - Commercial Break (A phpAds Primer)
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Commercial Break (A phpAds Primer)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-07-30

    Table of Contents:
  • Commercial Break (A phpAds Primer)
  • Getting Started
  • The Toy Store
  • Different Strokes
  • Room With A View()
  • The Advanced Course
  • Access Denied
  • The Number Game
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Commercial Break (A phpAds Primer) - The Advanced Course


    (Page 6 of 9 )

    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


     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway