php 转换sql查询语句的的编码,转换sql 特殊字符

public string filtRiskChar(string str) //过滤非法字符

{

string s = "";

s = str.Replace("'", " ");

s = s.Replace(";", " ");

s = s.Replace("1=1", " ");

s = s.Replace("|", " ");

s = s.Replace("

s = s.Replace(">", " ");

return s;

}

9ba35ca96da01b9d8696bb63cc50c813.gif

public boolean checkParameter(String para)

//检测

非法字符

24f2951ed0f4a17ea5fcd1b5e5fe5adf.gif    {

3722ac4e3698bc6f8b1aa40cdb531e17.gif        

int flag = 0;

3722ac4e3698bc6f8b1aa40cdb531e17.gif         flag += para.indexOf("'") + 1;

3722ac4e3698bc6f8b1aa40cdb531e17.gif         flag += para.indexOf(";") + 1;

3722ac4e3698bc6f8b1aa40cdb531e17.gif         flag += para.indexOf("1=1") + 1;

3722ac4e3698bc6f8b1aa40cdb531e17.gif         flag += para.indexOf("|") + 1;

3722ac4e3698bc6f8b1aa40cdb531e17.gif         flag += para.indexOf("

3722ac4e3698bc6f8b1aa40cdb531e17.gif         flag += para.indexOf(">") + 1;

3722ac4e3698bc6f8b1aa40cdb531e17.gif        

if (flag != 0)

e9698bc78676bbab2c25ab8ee88c43ab.gif        {

3722ac4e3698bc6f8b1aa40cdb531e17.gif             System.

out.println("提交了非法字符!!!");

3722ac4e3698bc6f8b1aa40cdb531e17.gif            

return

false;

816dfd4229cd5200b4469f8d41fceaa8.gif         }

3722ac4e3698bc6f8b1aa40cdb531e17.gif        

return

true;

39d5e2bd22c40d7b4fd2326b3faa0df2.gif     }

'过滤SQL非法字符并格式化html代码

function Replace_Text(fString)

if isnull(fString) then

Replace_Text=""

exit function

else

fString=trim(fString)

fString=replace(fString,"'","''")

fString=replace(fString,";",";")

fString=replace(fString,"--","—")

fString=server.htmlencode(fString)

Replace_Text=fString

end if

end function

function changechr(str)

changechr=replace(replace(replace(replace(str,"",">"),chr(13),"
")," "," ")

changechr=replace(replace(replace(replace(changechr,"[sayyes]","

),"),"[red]"," "),"[big]","") 

changechr=replace(replace(replace(replace(changechr,"[/sayyes]",">

"),"",""),"[/red]",""),"[/big]","")

end function

'会员发布的各种信息过滤

'Function Replace_Text(fString)

'If Not IsNull(fString) Then

'fString = trim(fString)

'fString = replace(fString, ";", ";")     '分号过滤

'fString = replace(fString, "--", "——") '--过滤

'fString = replace(fString, "%20", "")    '特殊字符过滤

'fString = replace(fString, "==", "")     '==过滤

'fString = replace(fString, ">", ">")

'fString = replace(fString, "

'fString = Replace(fString, CHR(32), " ")   ' 

'fString = Replace(fString, CHR(9), " ")    ' 

'fString = Replace(fString, CHR(34), """)

'fString = Replace(fString, CHR(39), "'") '单引号过滤

'fString = Replace(fString, CHR(13), "")

'fString = Replace(fString, CHR(10) & CHR(10), "

")

'fString = Replace(fString, CHR(10), "
")

'Replace_Text = fString

'End If

'End Function

'过滤SQL非法字符

Function checkStr(Chkstr)

dim Str:Str=Chkstr

if isnull(Str) then

checkStr = ""

exit Function

else

Str=replace(Str,"'","")

Str=replace(Str,";","")

Str=replace(Str,"--","")

checkStr=Str

end if

End Function

'检测传递的参数是否为数字型

Function Chkrequest(Para)

Chkrequest=False

If Not (IsNull(Para) or Trim(Para)="" or Not IsNumeric(Para)) Then

Chkrequest=True

End If

End Function

'检测传递的参数是否为日期型

Function Chkrequestdate(Para)

Chkrequestdate=False

If Not (IsNull(Para) or Trim(Para)="" or Not IsDate(Para)) Then

Chkrequestdate=True

End If

End Function

'得到当前页面的地址

Function GetUrl()

On Error Resume Next

Dim strTemp

If LCase(Request.ServerVariables("HTTPS")) = "off" Then

strTemp = "http://"

Else

strTemp = "https://"

End If

strTemp = strTemp & CheckStr(Request.ServerVariables("SERVER_NAME"))

If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & CheckStr(Request.ServerVariables("SERVER_PORT"))

strTemp = strTemp & CheckStr(Request.ServerVariables("URL"))

If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & CheckStr(Trim(Request.QueryString))

GetUrl = strTemp

End Function

'Function CheckReferer()   '检查用户是否在浏览器里输入了本页的地址

'     Dim sReferer, Icheck

'     CheckReferer = True

'     sReferer = Request.ServerVariables("HTTP_REFERER")

'     ServerIP = Request.ServerVariables("LOCAL_ADDR")

'     Icheck = InStr(sReferer, "ServerIP")

'     If Icheck = 0 Then

'     CheckReferer = False

'     End If

'End Function

'日期格式化

Function FormatDate(DT,tp)

dim Y,M,D

Y=Year(DT)

M=month(DT)

D=Day(DT)

if M<10 then M="0"&M

if D<10 then D="0"&D

select case tp

case 1 FormatDate=Y&"年"&M&"月"&D&"日"

case 2 FormatDate=Y&"-"&M&"-"&D

end select

End Function

转自 http://www.cnblogs.com/luheng/archive/2009/03/19/1416682.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值