Helping Alberta Flag  
business thrive on the web.
 

Home Hosting Plans-shared Hosting-Ecommerce Dedicated Servers Domain Registration Web Design Internet Access Resellers Terms & AUP Consulting Support

 
info@chinookwebs.com  403.257.1357   Support: 403-257-6263
 

Scripting- ASP & ASP.Net

 

 
 
New script by Tim McKay- News letter sign up script using ADO
New a simple way to password protect pages

ASP script samples:  Survey or Poll       - Banner Ads with tracking   Size, Height, Width of Image files

Survey Says!:

This script is designed to take a simple poll ( in this case a big brother poll).

The form action assumes that the script is placed on a page called poll.asp, but it could easily be placed on any page so long as you refer to that page in the action= line. In our example here, we created a database (table name= poll) with two columns and two rows. The first column is "which" and contains the two names on our poll (in this case Curtis and also Jordan), which we manually entered into the database.  The second column (numeric datatype) holds the number of votes for each of the "which" people. We have used a session variable (session("polled")) to limit the voting to one per session, and also to remove the voting button  once the visitor has voted.

Please feel free to use this script.

<%
dim p_resultstored(2)
dim p_whichstored(2)
dim j
If Request.Form("B1") = "Poll" Then
p_banish=Request.form("banished")
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "DSN=poll"
sqlText="select * from poll"
set rs=conn.Execute(sqlText)
response.write "<table>"
sql="update poll set results=" & p_updated & "where which='" & p_which & "' "
i=0
while not rs.EOF
p_resultstored(i)=rs.Fields("results")
p_whichstored(i)=Cstr(rs.Fields("which"))
If p_banish=p_whichstored(i) and session("polled")<>"yes" then
p_resultstored(i)=p_resultstored(i) + 1
sqlup="update poll set results=" & p_resultstored(i) & " where which ='" & p_whichstored(i) & "'"
conn.execute(sqlup)
total=total + p_resultstored(i)
i=i+1
rs.MoveNext
Wend
j=0
for j=o to (i-1)
response.write "<tr><td>Votes for:;" & p_whichstored(j) & "</td><td> (" & p_resultstored(j) & ")  </td><td>" & _ int((p_resultstored(j)/total)*100) & " %</td></tr>"    
next
response.write "<tr><td>Total votes = &nbsp;</td> " & "<td> (" & total & ")</td></tr></table>"
conn.close
set conn =Nothing
session("polled")="yes"
end if
%>
<form method="POST" action=poll.asp>
<p>Big Brother Survey:</p>
<p>Who do you think will be banished from the house:</p>
<p><input type="radio" value="Jordan" name="banished">Jordan   
'the value here must be the same in the database
<input type="radio" name="banished" value="Curtis">Curtis</p>      
'the value here must be the same in the database
<p>
<%
if session("polled")<>"yes" then
%>
<input type="submit" value="Poll" name="B1"></p>
<% end if %>
</form>

 

 
   
  Banner Ads with Tracking  
 
Let's start by listing the stuff you will need in order to make this work    
1. An object callled MSWC.AdRotator     If you are running IIS Ver4, it is not automatically included  but is on the IIS Server Resource Kit. The good news is that IIS5 includes it.
    
2. You will need a database, and this can be either Access or SQL    
    
3. You will need to  either set  a DSN or map the server path.   For the purposes of our example we are assuming a DSN. Within the database (we called it "ads") we created  a table called ad_log that contains two columns: Sponsor & Clickdate
    
4. You will need Active Server Page Support.   Comes built in with IIS4 & 5
    
5. For our purposes we chose to use GIF images as they are smaller and faster to load.    We picked 440x60 pixels as our default size for the banners.
  
6. Besides the actual banners themselves we created two files:    
adRotatorSched.txt   This is the file that the AdRotator is expecting to see
gotoSponsor.asp   Here is where we track each click.
To keep stuff neat and organized we put these two files and the banner images in a folder called ads    
  
7. Here is what the adRotatorSched.txt file contains:    
REDIRECT   http://www.shopmacleodtrail.com/ads/goToSponsor.asp

BORDER 0

*
/ads/banner1.gif
http://www.chinook-computers.com
Banner ads cheap $50/month
3
/ads/banner2.gif
http://www.chinook-computers.com
Banner ads cheap $50/month
2
/ads/banner3.gif
http://www.chinook-computers.com
Banner ads cheap $50/month
2
/ads/banner4.gif
http://www.chinook-computers.com
Banner ads cheap $50/month
3
/ads/banner5.gif
http://www.calgaryhumane.ab.ca
We support the humane society
2
/ads/banner1.gif
http://www.chinook-computers.com
banner ads cheap
1
  The first line redirects the "clickee" to our tracking page.  Depending on your monitor size this may appear on two lines but it should be coded as one line.

Next comes an optional border setting, followed by the all important asterisk.  The ad rotator next expects to see the path to whatever banner file is to be presented. After this it expects to see the hyperlink that will be followed. The next line is the text version. It is important to not leave this out, as the object expects certain lines in the correct order. The number that is all by itself following that represents the number of times out of the total that the banner will present itself.  So in this example we have a total of 13 presentations and the first banner will appear 3 out of 13 times(randomly).

    
8. Here is what the gotoSponsor.asp page contains:    
<%@ LANGUAGE="VBSCRIPT" %>

<%
sponsorURL = Request.querystring("url")
'create the object
set adstDB = Server.CreateObject("ADODB.Connection")
'Open the connection
adsDB.Open "ads"
'Insert the record here
sqlText = "insert into ad_log (sponsor, clickDate) values ('" 
sqlText =sqlText & sponsorURL
sqlText = sqlText & "','"
sqlText = sqlText & Now
sqlText = sqlText & "')"
adsDB.Execute(sqlText)

'Close the connection
adsDB.Close
'Destroy the connection
set adsDB = Nothing

Response.Redirect sponsorURL

%>

 

  This bit of script opens the database, inserts the URL that has been clicked (hyperlink line from the AdRotatorSched.txt  file), and also inserts the current time and date.  Don't forget to close the connection and destroy the objects. Once this page has finished its job of updating, it then redirects the clickee to the page they are supposed to go to, which is contained in the variable sponsorUrl.
  
9. Last but not least we have to present the banner on the page. This is done with a code snippet that can be placed just about anywhere.  Here it is:    
<%

set AdvObject = Server.CreateObject("MSWC.AdRotator")
adHTML = AdvObject.GetAdvertisement("/ads/AdRotatorSched.txt")
Response.Write adHTML

%>

 

 

Note: The page containing the code snippet above must have an asp extension  for example this page is aspscript.asp.    
  
Have a good time creating and tracking banners.  In the near future we will create a reporting module that retrieves, sorts and totals the information that has been saved into the "ads" database. We originally learned about this method from Nicholas Chase's book, "Active Server Pages 3. from scratch"
 
     
 
  :::: Privacy Policy
 
 
Home Overview Hosting-shared Hosting-Ecommerce Hosting-Semi Dedicated Domain Registration
Web Development Internet Access Resellers Terms & AUP Consulting About Us
FrontPage Support Chinook Store Scripting Technical Overview