利用泛解析实现二级域名原理
现在有些服务商提供了注册一个顶级域名送20个二级域名的服务,可是有的站长会觉得
不够用,其实可以通过程序自己做二级域名,就象 126.com一样。
一,泛域名
最重要的,你需要一个泛域名,泛域名是指DNS会把所有xxx.domain.com(xxx是任意字
符)形式的域名全部解析到一个指定IP地址,没有这个条件,下面的就不用想了,前面说
的送20个子域名,那是在DNS上设置的,并不是泛域名。怎么知道你的域名是不是泛域名
呢?比如 126.com,在浏览器地址栏输入www.126.com 或 126.com时,可以看到正确的
首页面,如果是输入 xxx.126.com (xxx是任意字符),浏览器就找不到地址了,那么
这就不是泛域名。怎么才能得到泛域名呢?如果你已经有一个域名,而且注册时没有特
别说明,那你就不用试了,肯定不支持的,我还没发现哪个域名商现在是默认支持泛域
名的,都是要你特别提出,并且要加钱才可以的。 当你要注册顶级域名之前,要问清楚
这个域名商是否可以给你泛域名,以及要加多少钱,我发现有的域名商根本就不支持泛
域名,甚至有的商家或代理根本不知道这么回事(晕倒)。所以你一定要先问清楚哦。
二,域名管理系统
1.域名管理系统主要是一个解析程序。工作原理是:
1)接收指向默认网站的URL;
2)分析URL数据,看他是不是已经注册过的;
3)如果是注册过的,从数据库中提取用户指定的二级域名指向;重定向过去或者隐含框
架就行了.
2. 一个域名管理系统几个基本要求是要满足
1、用户可以自己申请和管理
2、可以选择是隐含框架还是转向
3、如果是隐含框架,用户可以自己改title
4、目标路径允许的字符数要尽可能多
5、yourname.netmiss.net ,这里的yourname允许的字符也要尽可能多.
3.一段简单的解析程序:(是隐含框架的)
<!--#include file="conn.asp"-->
<%
dim geturl
geturl=replace(Request.ServerVariables("HTTP_HOST"),"www.","")
set rs=server.createobject("adodb.recordset")
sql="select * from tb where nowurl=''"&geturl&"''"
rs.open sql,conn,1,1
if rs.eof then
response.redirect"http://www.51bxg.com/miss.html;
else
dim tourl,company
tourl=rs("tourl")
company=rs("company")
%>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<META CONTENT="text/html; CHARSET=UTF-8" HTTP-EQUIV="Content-Type">
<TITLE><% =company %></TITLE>
</HEAD>
<frameset frameborder="0" framespacing="0" scrolling="no" border="0"
marginheight="0" marginwidth="0" rows="0,*">
<frame scrolling="NO" noresize="0" marginwidth="0" marginheight="0"
framespacing="0" frameborder="0" target="main" name="main"
SRC="about:blank">
<frame scrolling="yes" noresize="0" marginwidth="0" marginheight="0"
framespacing="0" frameborder="0" target="main" name="main" SRC="<% =tourl %
>">
<noframes>
<body>
This page uses frames, but your browser doesn''t support them.</body>
</noframes>
</frameset>
</HTML>
<% end if %>
三,支持上面两个条件的主机
最好有一台独立的服务器。泛解析的域名指向该服务器。如果是虚拟主机的话,就要向虚
拟主机提供商问清楚虚拟空间是否满足1,2两个条件.
一个域名管理系统的例子(并不完整,有兴趣的朋友可以到网上找一下玩整的程序,这种程序很多)
一个域名管理系统几个基本要求是要满足:
a,可以限制申请域名的敏感字,比如 hacker,wwww,sex,china等
b, 可以限制申请域名的非法字,比如:!·#¥%……—*()——?‘“/等
c, 每个地址只能申请一个域名。
d,限制申请域名的长度,
e, 如果用户所访问的域名没人申请则转到特定的页面,本例中的http://www.***.com/miss.html
f, 申请了域名:***.yourname.com 可以同时支持:http://***.yourname.com 以及http://www.***.youranme.com 两个域名的访问。
一下为系列程序代码:
shenqing.htm
<form action=adddns.asp method=post name=Frm onSubmit="return check_input()"> <br> <font color=red>加*号为必填内容</font> <br>
您想注册的域名:
http://<input name="nowurl" size=12
style=" BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000; FONT-SIZE: 9pt"> .***.com
<br>
你实际的网站地址:
<input name="tourl" size=12
style=" BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000; FONT-SIZE: 9pt">
你要求显示的title:
<input name="company" size=12
style=" BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000; FONT-SIZE: 9pt">
<br>
<input type="submit" name="Submit" value=" 提 交 信 息 " style="border:1px double rgb(88,88,88);font:9pt">
<input type="reset" name="Reset" value=" 重 新 填 写 " style="border:1px double rgb(88,88,88);font:9pt">
</p>
</form>
添加记录页面add.asp
<!--#include file="char.inc"-->
<!--#include file="conn.asp"-->
<%
uID=request.cookies("*****")
%>
<%
dim nowurl,tourl,company,along,pbkey
nowurl=trim(request.form("nowurl"))+".***.com"
nurl=trim(request.form("nowurl"))
tourl=trim(request.form("tourl"))
company=trim(request.form("company"))
along=20
pbkey="www,sex,admin,w,ww,wwww,hacker,hack"
set rs=server.createobject("adodb.recordset")
sql="select * from dns where userid='"&uid&"'"
rs.open sql,conn,1,1
if not rs.EOF then
response.write"很抱歉,你已经申请过二级域名,每个用户只能申请一个二级域名!<br>你申请的二级域名是:http://"+rs("nowurl")
response.end
end if
set rs=server.createobject("adodb.recordset")
sql="select * from dns where nowurl='"&nowurl&"'"
rs.open sql,conn,1,1
if not rs.eof then
response.write"很抱歉,你申请的域名:http://"+nowurl+"已经被其他公司申请,请另外申请域名。"
response.end
end if
if len(nurl)>along then
response.write"很抱歉,你输入的域名太长,请重新输入"
response.end
end if
if instr(pbkey,nurl) then
response.write"很抱歉,你输入的域名因为含有敏感字而不管理员屏蔽,请重新输入。"
response.end
end if
'判断字符的合法性
if instr(nurl,"~") or instr(nurl,"`") or instr(nurl,"/") or instr(nurl,"?") or instr(nurl,">") or instr(nurl,"<") or instr(nurl,";") or instr(nurl,":") or instr(nurl,"}") or instr(nurl,"{") or instr(nurl,")") or instr(nurl,"(") or instr(nurl,"*") or instr(nurl,"&") or instr(nurl,"^") or instr(nurl,"%") or instr(nurl,".") or instr(nurl,",") or instr(nurl,"'") or instr(nurl,"~") or instr(nurl,"!") or instr(nurl,"$") then
response.write"很抱歉,你输入的域名含有非法字符,请重新输入,以下字符为非法字符:<br>~ ` / ? > < ; : } { ) ( * & ^ % $ # @ ! "
response.end
end if
set rs=server.createobject("adodb.recordset")
sql="select * from ** where theid is null"
rs.open sql,conn,3,3
rs.addnew
rs("userid")=uID
rs("nowurl")=nowurl
rs("tourl")=tourl
rs("company")=company
rs.update
response.write"祝贺,申请成功,你马上就可使用你的域名:http://"+nowurl
%>
域名解吸程序: freedns.asp
<!--#include file="conn.asp"-->
<%
dim geturl
geturl=replace(Request.ServerVariables("HTTP_HOST"),"www.","")
set rs=server.createobject("adodb.recordset")
sql="select * from tb where nowurl='"&geturl&"'"
rs.open sql,conn,1,1
if rs.eof then
response.redirect"http://www.****.com/miss.html"
else
dim tourl,company
tourl=rs("tourl")
company=rs("company")
%>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<META CONTENT="text/html; CHARSET=UTF-8" HTTP-EQUIV="Content-Type">
<TITLE><% =company %></TITLE>
</HEAD>
<frameset frameborder="0" framespacing="0" scrolling="no" border="0" marginheight="0" marginwidth="0" rows="0,*">
<frame scrolling="NO" noresize="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" target="main" name="main" SRC="about:blank">
<frame scrolling="yes" noresize="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" target="main" name="main" SRC="<% =tourl %>">
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p></body>
</noframes>
</frameset>
</HTML>
<% end if %>
http://info-lib.net/post/%E5%88%A9%E7%94%A8%E6%B3%9B%E8%A7%A3%E6%9E%90%E5%AE%9E%E7%8E%B0%E4%BA%8C%E7%BA%A7%E5%9F%9F%E5%90%8D%E5%8E%9F%E7%90%86%E4%BB%A5%E5%8F%8A%E7%A8%8B%E5%BA%8F.html
用下面的代码
sURL=Request.ServerVariables("HTTP_HosT")
first_name=split(sURL,".")
if ubound(first_name)>2 then
Response.Status= "404 no found"
Response.End
end if
user_id=first_name(0)
这样取出的user_id就是用户名了
^_^