欢迎光临
我们一直在努力

制作一个简单的广告系统

建站超值云服务器,限时71元/月

by manohar kamath

august 9, 1999

creating a advertisement rotator page is easy – asp comes with an adrotator component thats easy to use.

the component, called adrotator, is installed when you install asp. the component has been a part of asp

installation since the first version of asp.

there are 3 parts to the ad rotator system:

ad rotator logic page

ad images date file

redirection page

ad rotator logic page

create a file say ads.inc, an include file that can be included on any asp page on your site. this file

will actually "create" the image links on the asp pages. the page makes use of the file in item 2, the ad

images data file to choose the image from the list of images.

the code is as shown below. i created a function getad() so that this function can be called within any

asp page where you want the banners to show up. the advantage of putting the logic in the function is

obvious – reuseability of code.

<script language=vbscript runat=server>

function getad()

dim load

create an instance of the adrotator component

set load = server.createobject("mswc.adrotator")

set the target frame, if any. this is the frame the where ad

url will open up. if the html page does not find the target name

the url will be opened in a new window

load.targetframe = "target=new"

get a random avertisement from the text file

this file is in the /ad folder

getad = load.getadvertisement("/ad/adrotator.txt")

end function

</script>

ad images data file

create the ad information file, say adrotator.txt. this file has two parts

general information for all the images – this information is applied to all images that are rotated. this

section contains 4 parts

redirect – the page that will handle the redirects. you can specify a absolute or a relative url for this

page

width – width of the images. if not specified, defaults to 60

height – height of images. if not specified, defaults to 440

border of the image. if not specified, defaults to 1

individual image information. this section is separated from the first by a single "*" on a separate line

as shown in the code below. this section has four parts

image source – either absolute, relative or a url like http://…

redirect url – the url to be sent when the user clicks on the image

alternate text – a brief description of the ad that appears in text browsers, or when the images are

turned off

ad weight – a number between 0 and 4,294,967,295 that determines the frequency of that ad display. a

weight of 0 means the ad will never be displayed. higher the number, more frequent the display is.

e.g. in the example below, the weights of two images are 2 and 3. so, the second image is 3 times more

likely to appear for every 2 appearance of first.

assuming the images are in the /images directory, a sample adrotator.txt file is shown below. the *

separates the general data from the image info. within the images info, leave a blank line between each

image data.

redirect adredir.asp

width 468

height 60

border 0

*

/images/fp2000.gif

http://www.microsoft.com/frontpage

microsoft frontpage 2000

2

/images/office2000.gif

http://www.microsoft.com/office

office 2000

3

redirection page

the redirection page, receives in its querystring, a variable named url that contains the url to redirect

to, and another variable image that contains the image url of the ad image. the image variable is more for

statistical purposes, to keep count of what image appeared when and how many times etc. so, if you were to

keep count of what images were clicked, you would log this into a database (there are better ways, but

just trying to illustrate why the variable is passed).

a simple redirect page, adredir.asp, is as follows. it essentially retrieves the url from the querystring

and does a response.redirect to it.

<%@language=vbscript %>

<%

set the response buffer on

response.buffer = true

dim lsurl

obtain the url from the querystring

lsurl = request.querystring("url")

clear the response and redirect to url

response.clear()

response.redirect(lsurl)

%>

using the system

include the file ads.inc on any asp page you want to show the banner ad. then, on the page, call the

function getad() at any point, however times you like to create as many ad banners. an example is as shown

below:

<!–#include virtual="/ad/ads.inc"–>

<html>

..

<!–the ad banner goes here–>

<p><%=getad()%></p>



</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 制作一个简单的广告系统
分享到: 更多 (0)