ASP讀取Request.QueryString編碼的函數(shù)代碼
更新時間:2011年09月19日 20:55:38 作者:
ASP讀取Request.QueryString編碼的函數(shù)代碼,學(xué)習(xí)asp的朋友可以參考下。
1. 支持參數(shù)純漢字 ?a=深山老熊
2. 支持參數(shù)gb2312 Urlencode編碼: ?a=%C9%EE%C9%BD%C0%CF%D0%DC
3. 支持參數(shù)UTF-8 Urlencode編碼: ?a=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Option Explicit
Const YXCMS_CHARSET = "UTF-8"
Const YXCMS_CODEPAGE = 65001
Response.CharSet = "UTF-8"
Session.CodePage = 65001
'測試URL
'?n1=深山老熊&n2=%C9%EE%C9%BD%C0%CF%D0%DC&n3=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
'深山老熊
'GBK : %C9%EE%C9%BD%C0%CF%D0%DC
'UTF-8 : %E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
Dim URI,key
Set URI = new Cls_URI
'輸出所有參數(shù)測試
For Each key In URI.QueryString
Response.Write "<span style='color:red'>" & key & " : </span>" & URI.Get(key) & "<hr/>"
Next
'取單個值
'URI.Get("名稱")
'--------------------------------------------
'ASP UTF-8編碼下通吃 GBK UTF-8編碼
'作者: 深山老熊 QQ:81090
'--------------------------------------------
Class Cls_URI
Private o_item,o_regx
Private url_query
Private Sub Class_Initialize
Set o_item = CreateObject("Scripting.Dictionary")
o_item.CompareMode = 1
Set o_regx = New Regexp
o_regx.Pattern = "^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$"
Session.CodePage = 936
url_query = Request.ServerVariables("QUERY_STRING")
Session.CodePage = 65001
'根據(jù)QUERY_STRING字符串,生成模擬QueryString值
Dim i,a,b,c,n,v
a = Split(url_query,"&") : c = UBound(a)
For i = 0 To c
b = Split(a(i),"=",2)
n = Trim(b(0) & "")
If UBound(b) < 1 Then
v = ""
Else
v = b(1)
If InStr(v,"%") > 0 Then v = URLDecode(v)
End If
If n <> "" Then
o_item(n) = v
End If
Next
Set o_regx = Nothing
End Sub
Private Sub Class_Terminate
Set o_item = Nothing
End Sub
'模擬 Request.QueryString
Public Function QueryString()
Set QueryString = o_item
End Function
'模擬 Request.QueryString(n)
Public Function [GET](n)
If o_item.Exists(n) Then
[GET] = o_item.Item(n)
Else
[GET] = ""
End If
End Function
'編碼格式化
Private Function URLDecode(ByVal s)
Dim sm,cs,r,o_regex
If Trim(s & "") = "" Then
URLDecode = s : Exit Function
End If
s = unescape(s)
If o_regx.Test(s) Then
cs = "UTF-8"
Else
cs = "GBK"
End If
Set sm = CreateObject("Adodb.Stream")
With sm
.Type = 2
.Mode = 3
.Open
.CharSet = "ISO-8859-1"
.WriteText s
.Position = 0
.CharSet = cs
URLDecode = .ReadText(-1)
.Close
End With
Set sm = Nothing
End Function
End Class
%>
2. 支持參數(shù)gb2312 Urlencode編碼: ?a=%C9%EE%C9%BD%C0%CF%D0%DC
3. 支持參數(shù)UTF-8 Urlencode編碼: ?a=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
復(fù)制代碼 代碼如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Option Explicit
Const YXCMS_CHARSET = "UTF-8"
Const YXCMS_CODEPAGE = 65001
Response.CharSet = "UTF-8"
Session.CodePage = 65001
'測試URL
'?n1=深山老熊&n2=%C9%EE%C9%BD%C0%CF%D0%DC&n3=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
'深山老熊
'GBK : %C9%EE%C9%BD%C0%CF%D0%DC
'UTF-8 : %E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A
Dim URI,key
Set URI = new Cls_URI
'輸出所有參數(shù)測試
For Each key In URI.QueryString
Response.Write "<span style='color:red'>" & key & " : </span>" & URI.Get(key) & "<hr/>"
Next
'取單個值
'URI.Get("名稱")
'--------------------------------------------
'ASP UTF-8編碼下通吃 GBK UTF-8編碼
'作者: 深山老熊 QQ:81090
'--------------------------------------------
Class Cls_URI
Private o_item,o_regx
Private url_query
Private Sub Class_Initialize
Set o_item = CreateObject("Scripting.Dictionary")
o_item.CompareMode = 1
Set o_regx = New Regexp
o_regx.Pattern = "^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$"
Session.CodePage = 936
url_query = Request.ServerVariables("QUERY_STRING")
Session.CodePage = 65001
'根據(jù)QUERY_STRING字符串,生成模擬QueryString值
Dim i,a,b,c,n,v
a = Split(url_query,"&") : c = UBound(a)
For i = 0 To c
b = Split(a(i),"=",2)
n = Trim(b(0) & "")
If UBound(b) < 1 Then
v = ""
Else
v = b(1)
If InStr(v,"%") > 0 Then v = URLDecode(v)
End If
If n <> "" Then
o_item(n) = v
End If
Next
Set o_regx = Nothing
End Sub
Private Sub Class_Terminate
Set o_item = Nothing
End Sub
'模擬 Request.QueryString
Public Function QueryString()
Set QueryString = o_item
End Function
'模擬 Request.QueryString(n)
Public Function [GET](n)
If o_item.Exists(n) Then
[GET] = o_item.Item(n)
Else
[GET] = ""
End If
End Function
'編碼格式化
Private Function URLDecode(ByVal s)
Dim sm,cs,r,o_regex
If Trim(s & "") = "" Then
URLDecode = s : Exit Function
End If
s = unescape(s)
If o_regx.Test(s) Then
cs = "UTF-8"
Else
cs = "GBK"
End If
Set sm = CreateObject("Adodb.Stream")
With sm
.Type = 2
.Mode = 3
.Open
.CharSet = "ISO-8859-1"
.WriteText s
.Position = 0
.CharSet = cs
URLDecode = .ReadText(-1)
.Close
End With
Set sm = Nothing
End Function
End Class
%>
您可能感興趣的文章:
- asp下request.querystring("id")與request("id")區(qū)別
- asp.net下Request.QueryString取不到值的解決方法
- 循環(huán)取值Request.QueryString的用法
- 從客戶端檢測到有潛在危險的Request.Form值的asp.net代碼
- asp.net 從客戶端中檢測到有潛在危險的 Request.Form 值錯誤解
- ASP.NET中Request.Form中文亂碼的解決方法
- asp.net中Request.QueryString與Request.Param的區(qū)別分析
- Request.QueryString與一般NameValueCollection的區(qū)別
- 有潛在危險的 Request.Form 值避免方法
- ASP.NET從客戶端中檢測到有潛在危險的request.form值的3種解決方法
- ASP.NET檢測到不安全 Request.Form 值解決方案匯總
- Jquery中request和request.form和request.querystring的區(qū)別
相關(guān)文章
ASP:ActiveX不能創(chuàng)建Scripting.FileSystemObject對象解決辦法
關(guān)于ActiveX不能創(chuàng)建Scripting.FileSystemObject對象的類似問題,大體上解決辦法都是類似的,主要是思想要清晰:首先考慮組件注冊問題,其次是組件權(quán)限問題,如果服務(wù)器配置沒有問題的話,那就仔細檢查一下你的程序源碼吧2011-11-11ASP新聞分頁,將一篇過長的文章分頁,生成靜態(tài)頁面
現(xiàn)在將他們生成靜態(tài)頁面沒有什么問題,但是如何將它們按照某種規(guī)則,生成編號為20030405-1.htm 20030405-2.htm 20030405-3.htm這樣的靜態(tài)文件呢?2008-11-11檢查上傳圖片是否合法的函數(shù),木馬改后綴名、圖片加惡意代碼均逃不過
很多ASP程序檢查上傳圖片是否合法往往只去檢查文件的后綴,這樣有一個很大的安全隱患,就是如果把ASP文件的后綴名改成.jpg或者.gif上傳,或者圖片里加入惡意代碼再上傳,那也會被程序認(rèn)為是圖片文件而照傳不誤。假如不懷好意的人上傳個木馬文件進去,雖然是后綴為jpg也許無法直接運行,但確確實實給服務(wù)器帶來了很大的安全隱患。2008-03-03ASP的URLDecode函數(shù)URLEncode解碼函數(shù)
我們知道,ASP的Server對象有個URLEncode方法可以對地址進行編碼,但卻沒有相應(yīng)的解碼函數(shù),下邊的這個函數(shù)可以實現(xiàn)對URLEncode的解碼。2010-12-12在ASP中不用模板生成HTML靜態(tài)頁直接生成.html頁面
有沒有辦法不用模板,如一個正常的htmer.asp頁面,直接生成為htmer.html頁面呢?當(dāng)然是可以的,而且非常簡單,今天就教大家在ASP中不用模板生成HTML靜態(tài)頁的方法2014-09-09asp下request.querystring("id")與request("id&quo
一下問題一天遇到2次,復(fù)制過來以供下次參考,一般來說還使用萬能的request("id")比較好2008-01-01