欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

动态广告管理程序制作例子

程序员文章站 2022-08-09 19:01:53
by wayne berry this issuemany sites that are content specific depend on banner advertisement for re...
by wayne berry
this issue
many sites that are content specific depend on banner advertisement for revenue. such is the case for 15
seconds. a banner is displayed at the top of the page for every page viewed. clients usually buy a set
number of banner impressions and these impressions are rotated amongst all the clients over a period of
time. in order to do this there must be a dynamic quality to the banners. in other words, the banner to
display is not determined until that page is requested.
with an active server page this is an easy task. active server pages are dynamic and there are many
components that handle the task of banner rotation. a simple one comes free with the internet information
server, and more complicated rotation schedules can be done with site server and other third party
components. this article is not about how to implement these components within your active server pages,
since this is a fairly easy task.

this article will describe how to implement a banner rotation scenario where the pages served are static,
i.e. .htm, and do not have the flexibility to call components. the task is to dynamically serve banners
and statically serve pages. this is the opposite of the scenario for banner rotation components, which
statically serve banners and dynamically serve pages.

one trick
there is only one trick here and once you know it the rest is pretty straightforward. internet explorer
and netscape allow you to refer to an active server page within an image tag. example 1 demonstrates the
html to be inserted in the static page.
example 1 : html banner reference



< img src="https://www.myserver.com/servebanner.">


once you have referred to a dynamic active server page with the static page, you need to build an active
server page to return an image, in this case a banner. example 2 shows the code to use for servebanner.asp
which is called in example 1.

example 2 : servebanner.asp source



<%
response.redirect("https://www.myserver.com/banner.gif")
%>


these two pages combined will allow you to display to the user a banner as if you referred directly to the
banner image instead of an active server page. in order to do banner rotation all you have to do is expand
example 2 so different images come up every time servebanner.asp is called.

adding the element of rotation.
with this technique the dynamic aspect of the banner rotation is controlled within the active server page
that the img tag is referring to. in order to randomly rotate the banners you will need to change
serverbanner.asp to choose a different banner each time that it is called. example 3 shows how to do this.
example 3 : rotating banners



<%

dim array(2)

initialize the vbscript random
number generator
randomize

array(1)="https://www.myserver.com/banner1.gif"
array(2)="https://www.myserver.com/banner2.gif"

upperbound=ubound(array)
lowerbound=1
lrandom = int((upperbound - lowerbound + 1) * rnd + lowerbound)