Asp解决URL中文编解码问题
作者:cnfgg 日期:2009-08-20
解决方案如下:
在发送激活邮件前使用UrlEncode函数(此函数为ASP内部函数)给用户名加密。
代码为:
username=Server.UrlEncode(username)
激活URL链接为
activeuser.asp?userName="&username&"&userpassword="&userpass&"&checkcode="&checkcode
在验证激活页面使用UrlDecode函数(此函数需自己写)为你使用UrlEncode函数加密过的变量解密
代码为:
userName=URLDecode(userName)
这样就大功告成!
附UrlDecode函数(可以解密中文)
复制内容到剪贴板
程序代码
程序代码Function URLDecode(ByVal strIn)
URLDecode = ""
Dim sl: sl = 1
Dim tl: tl = 1
Dim key: key = "%"
Dim kl: kl = Len(key)
sl = InStr(sl, strIn, key, 1)
Do While sl>0
If (tl=1 And sl<>1) or tl<sl Then
URLDecode = URLDecode & Mid(strIn, tl, sl-tl)
End If
Dim hh, hi, hl
Dim a
Select Case UCase(Mid(strIn, sl+kl, 1))
Case "U":'Unicode URLEncode
a = Mid(strIn, sl+kl+1, 4)
URLDecode = URLDecode & ChrW("&H" & a)
sl = sl + 6
Case "E":'UTF-8 URLEncode
hh = Mid(strIn, sl+kl, 2)
a = Int("&H" & hh)'ascii码
If Abs(a)<128 Then
sl = sl + 3
URLDecode = URLDecode & Chr(a)
Else
hi = Mid(strIn, sl+3+kl, 2)
hl = Mid(strIn, sl+6+kl, 2)
a = ("&H" & hh And &H0F) * 2 ^12 or ("&H" & hi And &H3F) * 2 ^ 6 or ("&H" & hl And &H3F)
If a<0 Then a = a + 65536
URLDecode = URLDecode & ChrW(a)
sl = sl + 9
End If
Case Else:'Asc URLEncode
hh = Mid(strIn, sl+kl, 2)'高位
a = Int("&H" & hh)'ascii码
If Abs(a)<128 Then
sl = sl + 3
Else
hi = Mid(strIn, sl+3+kl, 2)'低位
a = Int("&H" & hh & hi)'非ascii码
sl = sl + 6
End If
URLDecode = URLDecode & Chr(a)
End Select
tl = sl
sl = InStr(sl, strIn, key, 1)
Loop
URLDecode = URLDecode & Mid(strIn, tl)
End Function
评论: 1 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志:
嗯,不错!