用ASP实现动态IP转向
数码时尚
现在网络上免费ASP空间几乎没有,收费ASP空间也往往有容量限制,无法满足大家的需求。随着宽带的普及,架设一台个人服务器就能较好解决这一问题。由于个人宽带用户的IP地址多是动态分配的,所以,要经常更新网站的IP地址。这里我们可以结合原有的ASP空间,利用数据库实现这一功能。
建立一个Access数据库文件“music.mdb”并创建表“server”,设置两个字段:“serip”与“adminpass”。其中“adninpass”内容为启动服务器的管理员密码,启动服务器的程序如下:
<%
dim cn,conn
'取得管理员的密码
pass=request.form("pass")
'密码不为空则连接数据库进行判断
if pass<>"" then
'创建数据库连接对象连接数据库
set cn=server.createobject("adodb.connection")
conn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&server.mappath("music.mdb")+""
cn.open conn
'创建SQL查询检验管理员密码
sql="select * from server where pass like '"&pass&"'"
set rs=cn.Execute(sql)
if not rs.eof then
'管理员密码正确则取得访问者IP地址,此为管理员本地计算机IP地址
ipaddress=Request.ServerVariables("REMOTE_ADDR")
'创建SQL更新数据库IP地址记录
strsql="update server set serip='"&ipaddress&"' where pass like '"&pass&"'"
cn.Execute(strsql)
'调用script关闭当前窗口
response.write "<script>setTimeout('self.close()',1000)</script>"
else response.write "对不起,密码不正确!"
end if
'密码为空则显示输入表单要求输入管理员密码
else
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<table border="0" width="100%"cellspacing="0" cellpadding="0">
<tr><td width="100%" height=18></td></tr>
<tr><td width="100%" align="center">
<form method="POST" action="runserver.asp" style="margin-bottom:0px;margin-right:-5px">
请输入密码:<input type="password" name=pass size=7><br>
<input type="submit" value="确定">
</form></td></tr>
<tr><td width="100%" height=5></td></tr>
</table>
</body>
</html>
<% end if%>
在你的计算机上安装PWS(Win98系统)或IIS(Win2000或XP系统),把程序及数据库上传到你的ASP空间。在网站首页上建立一个启动服务器的链接,以后一上网就点击此连接启动服务器,将你的计算机的IP地址存入数据库,这样你的计算机就成为网络上的一台别人可以访问的服务器了。现在已经将网页的连接指向本地计算机了,这样是不是想用多少空间都有了?