Free Simple Ad Rotator (.asp)
With this script we will be able to show to our visitors different ads each time they access a page from our server. The system is based in three different pages:
  • A file name "global.asa". This file is located must be located in the main directory within your site ("/global.asa"). Each time a new visitor requests a page in your, it will be assigned a variable name session("ad") with a given value (0). 
  • A file name "adrotator.asp" which will contain the information necessary to add different add to pages visited by clients. This file will allow to show up to 10 different ads to the client during the time he is connected to the server (during the time the session is active). The maximum number of ads may be easily changed. 
  • A simple SSI code we must include in our pages. 
The first file ("global.asa") is in the table. Just copy the code in the table to a text file and save it in the main directory of your site ("/global.asa").
global.asa
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart
End Sub

Sub Application_OnEnd
End Sub

Sub Session_OnStart
session("ad")=0
End Sub

Sub Session_OnEnd
End Sub

</SCRIPT>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Each time a new visitor gets to our pages (when a session starts), a value for session("ad") will be assigned (line 1o).

The second file ("adrotator.asp") will be used to add the code from different links to our pages. This file will look like this one: 

adrotator.asp
<%
if session("ad")=10 then
   session("ad")=1
else
   session("ad")=session("ad") 1
end if 
%>

<% Select Case session("ad") %>
<% case 1 %>
     <A HREF="url1.html"><IMG SRC="image1.gif"></A>
 <% case 2 %>
     <A HREF="url2.html"><IMG SRC="image2.gif"></A>
<% case 3 %>
     <A HREF="url3.html"><IMG SRC="image3.gif"></A>
<% case 4 %>
     <A HREF="url4.html"><IMG SRC="image4.gif"></A>
<% case 5 %>
     <A HREF="url5.html"><IMG SRC="image5.gif"></A>
<% case 6 %>
     <A HREF="url6.html"><IMG SRC="image6.gif"></A>
<% case 7 %>
     <A HREF="url7.html"><IMG SRC="image7.gif"></A>
<% case 8 %>
     <A HREF="url8.html"><IMG SRC="image8.gif"></A>
<% case 9 %>
     <A HREF="url9.html"><IMG SRC="image9.gif"></A>
<% case 10 %>
     <A HREF="url10.html"><IMG SRC="image10.gif"></A>
<% End select %>


 
In the script above there are some elements we must change.
  • In this example they may be included  up to 10 different ads. This maximum number of ads is defined in line 2 of the script, and also in the amount of links in red. We may easily modify this maximum amount ads.
  • In red are shown the links. You must change the html code defining those links with your links. As you can guest, any kind of link or html is allowed, so you may use this system to rotate banner links, text links or whatever.
Finally we must add this code to our pages. It may be done in two ways: 

Option 1

  • Create a file named "adrotator.asp" with the code above, save it to your server (p.e. "/adrotator.asp"), and use Server Site Include to include "adrotator.asp" to your regular pages this way:
index.asp
<html>
<head>
<title>My page</title>
</head>
<body bgcolor=FFFFFF>
<center>

<!--#include virtual="/adrotator.asp" -->

<p>This text is very interesting.

</center>
</body>
</html>

 

Option 2
  • Include the code in "adrotator.asp" above in your page (p.e. "index.asp" bellow).
index.asp
<html>
<head>
<title>My page</title>
</head>
<body bgcolor=FFFFFF>
<center>

<%
if session("ad")=10 then
   session("ad")=1
else
   session("ad")=session("ad") 1
end if 
%>

<% Select Case session("ad") %>
<% case 1 %>
     <A HREF="url1.html"><IMG SRC="image1.gif"></A>
 <% case 2 %>
     <A HREF="url2.html"><IMG SRC="image2.gif"></A>
<% case 3 %>
     <A HREF="url3.html"><IMG SRC="image3.gif"></A>
<% case 4 %>
     <A HREF="url4.html"><IMG SRC="image4.gif"></A>
<% case 5 %>
     <A HREF="url5.html"><IMG SRC="image5.gif"></A>
<% case 6 %>
     <A HREF="url6.html"><IMG SRC="image6.gif"></A>
<% case 7 %>
     <A HREF="url7.html"><IMG SRC="image7.gif"></A>
<% case 8 %>
     <A HREF="url8.html"><IMG SRC="image8.gif"></A>
<% case 9 %>
     <A HREF="url9.html"><IMG SRC="image9.gif"></A>
<% case 10 %>
     <A HREF="url10.html"><IMG SRC="image10.gif"></A>
<% End select %>

<p>This text is very interesting.

</center>
</body>
</html>


 

AspTutorial.info