samScripts.com
[Home] [My Scripts] [Contact] [Business Card Designer] [Donate] [$8.95 Domain Names]

Home > Scripts > EasyAds

EasyAds

... feel free to use this script for whatever you like.

EasyAds

Easy ads is a very simple banner ad (or any other html content) rotation system.
Features include multiple ad categories, easy administration script, ad weighting, and easy install.

Description:

Whilst lacking most of the features of a fully featured banner ad management system such as phpAdsNew, the EasyAds script is designed for simple, easy banner ad management.

Main Features


Multiple categories
Individual add weightings - ie weighing of 2 will cause an ad to be displayed twice as often as one with a weighting of 1
Easy usage
Simple administration script try it out here - username "demo" password "demo" - updating and deleting is disabled.
Remote banner hosting - It can be used for remote banner hosting - however, to work, you either need to use javascript to call the ad, or include it in an iframe or layer. See the included examples for more information, or just email me if its not clear.

Missing Features


EasyAds does not support:

Click tracking - I use it mainly for displaying ads from affiliate programs that provide their own tracking of clicks. If you need this, try something like phpAdsNew.
Any other more advanced features. Sorry :)

Installation


1st, either create a new database using your normal method, or pick an existing one to use. You then need to create the database tables that the script needs - the sql for this is in the easyads.sql file.

Next, edit the variables at the top of the easyadsadmin.php file to the correct values for your database, and the username and password you want to use:

<?php

$database
= "your_database";    // the name of the database the ads are stored in
$dbhost = "localhost";    // database host name for connecting
$dbuser = "your_database_username";    // username for connecting to the database
$dbpassword = "your_database_password";    // password for connecting to the database

$admin_user = "your_admin_username";    // username for editing the adverts
$admin_password = "your_admin_password";    // password for editing the adverts

...    ...   ...   ...   ...   ...   ...   ...   ...   ...   ...

?>


You can then use the easyadsadmin.php to add new categories, and ads to those categories.

Usage


Displaying ads is simple:

<?php

// include the php ad class script

include("./easyads.php");

// setup your database connection

$conn = mysql_connect("database_host", "database_username", "database_password") or die(mysql_error());

mysql_select_db("your_database");

// initialise the ads class with the database connection

$ads = new easyads($conn);

// display an ad from the "mainad" category

$ads->display("mainad");

?>


You can copy the database connection and ad class initialization code to the easyads.php class file for convenience. Here's an example of a simple page using that to display two banner ads:

<?php

include("./easyads.php");

// the following code could just be added to the easyads.php file so you don't need to retype it

$connection = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($databasename);

$ads = new easyads($connection);

?>
<html>
<head>
<title>Easy Ads Example</title>
</head>
<body>
<h2>There should be a banner ad below this</h2>

<?php $ads->display("topbanner"); ?>

<hr />
<h2>And another below this...</h2>

<?php $ads->display("bottombanner");?>

<hr />
Thats all folks...
</body>
</html>


The above code will display something like this...

Output:

There should be a banner ad below this

Order your credit report today

And another below this...

Hi! This is part of the banner ad - it contains html as well as an image: isn't that nice?
Thats all folks...


Easy :)

Multiple ads from the same category


If you are displaying several ads from the same category, you can "preload" them, so you only make one query on the database (speeds everything up a bit).

<?php

// include the ads class

include("./easyads.php");

// preload 3 ads from the "smallads" category

$ads->preload(3, "smallads");

// display the ads:

?>
<html>
<head><title>Ads Demo</title></head>
<body>
<table>
  <tr>
   <td><?php $ads->display("smallads");?></td>
   <td><?php $ads->display("smallads");?></td>
   <td><?php $ads->display("smallads");?></td>
  </tr>
</table>
</body>
</html>


Output:
Hello
Get YOUR 15 Minutes of Fame - MODELS.com Click here to post your resume


Displaying ads remotely


In some cases, you may want your ads database on a different server than your site - for example, you may have several different sites, but want to use the same ads on all of them, or alternately, you may not want to use php on every page with ads. In this case, you can call the ads script remotely, using a separate script to "serve" the ads, and javascript or frames to display the ad.

The two scripts included in the distribution, easyservejavascript.php, and easyservehtml.php can both be set up to serve ads remotely, either through javascript, or some other method.

Examples of using them are below, using scripts serving ads from www.jobresumes.net :

Using javascript to display the ads:

<html>
<head>
<title>Easy Ads Example</title>
</head>
<body>
<h2>There should be a banner ad below this</h2>
<script language="javascript" src="http://www.jobresumes.net/easyservejavascript.php?category=main banner"  ></script>
<hr />
<h2>And another below this...</h2>
<script language="javascript" src="http://www.jobresumes.net/easyservejavascript.php?category=main banner" ></script>
<hr />
</body>
</html>



Output

There should be a banner ad below this


And another below this...




Displaying ads remotely with iframes:

<html>
<head>
<title>Easy Ads Example</title>
</head>
<body>
<h2>There should be a banner ad below this</h2>
<iframe src="http://www.jobresumes.net/easyservehtml.php?category=main banner" width="500" height="70"></iframe>
<hr />
<h2>And another below this...</h2>
<iframe src="http://www.jobresumes.net/easyservehtml.php?category=main banner" width="500" height="70"></iframe>
<hr />
</body>
</html>


There should be a banner ad below this


And another below this...




There are two possible problems with using the remote methods: the javascript method relies on the visitor to your site having javascript enabled. If not, no ad will be shown. The iframe method requires you to predefine the size of the ad in advance. Oh, you'll probably need to ad the equivalent <layer> tag as well as iframe so the ad shows up in netscape, although I haven't tested it myself.

Well, good luck,

send any questions to easyads@samscripts.com .

Cheers, Sam

Files

easyads.zip (5928 bytes)