ASP'de dönüşümlü reklam yapmak

Öncelikle tablomuzu oluşturalım. ( SQL kullanıyoruz )

create table Banners ( BannerID int identity PRIMARY KEY, Image varchar(100), URL varchar(100), Hint varchar(100), Shown int, Clicked int, )

Bu kodları reklamın görüntülenmesini istediğimiz yere ekliyoruz:

<%@ Language=VBScript %>
<%
Response.Buffer=True ‘Define our ADO constants const adOpenStatic = 3 const adLockOptimistic = 3 ‘—– Create and Open Connection

Set MyConnection = Server.CreateObject("ADODB.Connection") MyConnection.ConnectionString = "PROVIDER=SQLOLEDB;SERVER=YourServerName;UID=YourUID;" & _ "PWD=YourPWD;DATABASE=YourDATABASE" MyConnection.Open '----- Pick Ad from database

SQLBanners = "Select * from Banners" Set Banners =

Server.CreateObject("ADODB.Recordset")

Banners.CursorType = adOpenStatic

Banners.LockType = adLockOptimistic

Banners.Open SQLBanners, MyConnection

Randomize Timer

Banners.Move Int(RND * CInt(Banners.RecordCount))

'----- Increment Shown field value

Banners("Shown") = Banners("Shown") + 1 Banners.Update

'----- Create and display Response

ImageString = "<img src=""" & Banners("Image") & """ alt=""" & Banners("Hint") & """>" ResponseString = "<a href=""RedirectMe.asp?URL=" & Banners("URL")

ResponseString = ResponseString & "&BannerID=" & Banners("BannerID") & """>" & ImageString & "</a>"

Response.Write ResponseString Response.End

'----- Clean up memory Banners.Close MyConnection.Close

Set Banners=Nothing Set MyConnection=Nothing %>

Aşağıdaki kod ise yönlendireceğiniz adresi gösterir

RedirectMe.asp

<%@ Language=VBScript %>
<%
Response.Buffer=True

‘Define our ADO constants
const adOpenStatic = 3
const adLockOptimistic = 3

‘—– Create and Open Connection
Set MyConnection = Server.CreateObject(“ADODB.Connection”)
MyConnection.ConnectionString = “PROVIDER=SQLOLEDB;SERVER=YourServerName;UID=YourUID;” &amp; _
“PWD=YourPWD;DATABASE=YourDATABASE”
MyConnection.Open

‘—– Increment Clicked field value
SQLBanners = “Select * from Banners Where BannerID=” &amp; Request.QueryString(“BannerID”)
Set Banners = Server.CreateObject(“ADODB.Recordset”)
Banners.CursorType = adOpenStatic
Banners.LockType = adLockOptimistic
Banners.Open SQLBanners, MyConnection
Banners(“Clicked”) = Banners(“Clicked”) + 1
Banners.Update
Response.Redirect(Request.QueryString(“URL”))
Response.End

‘—– Clean up memory
Banners.Close
MyConnection.Close
Set Banners=Nothing
Set MyConnection=Nothing
%>

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir