實現(xiàn)Web中的@虛擬域名系統(tǒng)(原理篇)(2)_Windows教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
下面是庫中的url表結構:
字段名 字段類型 字段默認值 //功能注釋
id int 自增 關鍵字 1 不用user做關鍵字是怕其中有中文字符
user 字符型 null 如BBS或GUESTBOOK的值
url 字符型 null 轉向的網(wǎng)址
click int 0 訪問量
表里的字段很少,只有4個,網(wǎng)友可以根據(jù)需要再增加一些功能字段,如是否有彈出窗口廣告,訪問量分析等。不過必要的就是user字段和url字段,因為我們必須要得到user的值,再根據(jù)它得到其轉向url網(wǎng)址,再在gourl.asp中實現(xiàn)轉向就行了。
下面是gourl.asp中實現(xiàn)轉向的全部程序(我會在程序中寫下注釋):
dim conn,dbs //定義變量
Set conn=Server.CreateObject("ADODB.Connection") //建立連接對象
dbs=server.mappath("url.mdb") //定義要連接的數(shù)據(jù)庫路徑
conn.open "driver={microsoft access driver (*.mdb)};dbq="&dbs //打開并實現(xiàn)其數(shù)據(jù)庫源的鏈接
user=trim(request.querystring("user")) //得到default.html文件中得到的在瀏覽器中輸入的網(wǎng)址
if user<>"" then //當user值不為空時
user=replace(user,"http://","") //將"http://"字符串從user值刪去
at=instr(user,"@") //將user值中"@"所在位置賦給變量at
else
response.write "信息出錯,請聯(lián)系moon!" //當user值為空時則告訴網(wǎng)友有錯
end if
if at>0 then
user=left(user,at-1) //當user值中"@"所在的位置大于0時,將其中的部分重賦給user,如"BBS"或" GUESTBOOK"等值
else
response.redirect "def.htm" //如果沒有得到其中的值,如打http://www.luyu.net時,就返回def.htm文件中。
response.end //停止輸出
end if
if user<>"" then
set rs=conn.execute("select url from dns where user='"&user&"'") //當user值不為空時,連接數(shù)據(jù)庫,將進行搜索
if not rs.eof then
conn.execute("update url set click=click+! Where user='"&user&"'")//當記錄不為空時,將此網(wǎng)站的訪問量加1
response.redirect rs("url") //再轉向其網(wǎng)站
else
response.write "抱歉,沒有這個網(wǎng)站!" //記錄為空時,警告網(wǎng)友沒有此網(wǎng)站
end if
set rs=nothing
else
response.write"抱歉,沒有這個域名!" //當user的值為空時,則警告網(wǎng)友沒有此域名
end if
set conn=nothing //關閉數(shù)據(jù)庫連接
如果想在訪問虛擬域名時做個彈出窗口,以幫自己做個廣告的話,可以在將上面的代碼改成:
<script>
window.open("http://luyu.net","網(wǎng)絡隨筆","width=350,height=450");
this.location = "gourl.asp?user=" + this.location.href;
</script>
好了,這樣一個域名訪問系統(tǒng)就簡單的做好了。如果和PHP或是JSP等來實現(xiàn)的話,原理也是一樣的,我相信大家看了這篇文章都可以做出來了。只是把gourl.asp文件改一下便可。
字段名 字段類型 字段默認值 //功能注釋
id int 自增 關鍵字 1 不用user做關鍵字是怕其中有中文字符
user 字符型 null 如BBS或GUESTBOOK的值
url 字符型 null 轉向的網(wǎng)址
click int 0 訪問量
表里的字段很少,只有4個,網(wǎng)友可以根據(jù)需要再增加一些功能字段,如是否有彈出窗口廣告,訪問量分析等。不過必要的就是user字段和url字段,因為我們必須要得到user的值,再根據(jù)它得到其轉向url網(wǎng)址,再在gourl.asp中實現(xiàn)轉向就行了。
下面是gourl.asp中實現(xiàn)轉向的全部程序(我會在程序中寫下注釋):
dim conn,dbs //定義變量
Set conn=Server.CreateObject("ADODB.Connection") //建立連接對象
dbs=server.mappath("url.mdb") //定義要連接的數(shù)據(jù)庫路徑
conn.open "driver={microsoft access driver (*.mdb)};dbq="&dbs //打開并實現(xiàn)其數(shù)據(jù)庫源的鏈接
user=trim(request.querystring("user")) //得到default.html文件中得到的在瀏覽器中輸入的網(wǎng)址
if user<>"" then //當user值不為空時
user=replace(user,"http://","") //將"http://"字符串從user值刪去
at=instr(user,"@") //將user值中"@"所在位置賦給變量at
else
response.write "信息出錯,請聯(lián)系moon!" //當user值為空時則告訴網(wǎng)友有錯
end if
if at>0 then
user=left(user,at-1) //當user值中"@"所在的位置大于0時,將其中的部分重賦給user,如"BBS"或" GUESTBOOK"等值
else
response.redirect "def.htm" //如果沒有得到其中的值,如打http://www.luyu.net時,就返回def.htm文件中。
response.end //停止輸出
end if
if user<>"" then
set rs=conn.execute("select url from dns where user='"&user&"'") //當user值不為空時,連接數(shù)據(jù)庫,將進行搜索
if not rs.eof then
conn.execute("update url set click=click+! Where user='"&user&"'")//當記錄不為空時,將此網(wǎng)站的訪問量加1
response.redirect rs("url") //再轉向其網(wǎng)站
else
response.write "抱歉,沒有這個網(wǎng)站!" //記錄為空時,警告網(wǎng)友沒有此網(wǎng)站
end if
set rs=nothing
else
response.write"抱歉,沒有這個域名!" //當user的值為空時,則警告網(wǎng)友沒有此域名
end if
set conn=nothing //關閉數(shù)據(jù)庫連接
如果想在訪問虛擬域名時做個彈出窗口,以幫自己做個廣告的話,可以在將上面的代碼改成:
<script>
window.open("http://luyu.net","網(wǎng)絡隨筆","width=350,height=450");
this.location = "gourl.asp?user=" + this.location.href;
</script>
好了,這樣一個域名訪問系統(tǒng)就簡單的做好了。如果和PHP或是JSP等來實現(xiàn)的話,原理也是一樣的,我相信大家看了這篇文章都可以做出來了。只是把gourl.asp文件改一下便可。
相關Windows教程:
- 相關鏈接:
- 教程說明:
Windows教程-實現(xiàn)Web中的@虛擬域名系統(tǒng)(原理篇)(2)
。