Php sql注入跨站攻击,防止sql注入与跨站攻击的代码分享(初级实用型)

以下代码实现:

对所有POST提交的参数数据,对参数中的内容进行校验,对包含非法字符的参数进行处理。

代码如下:

复制代码 代码示例:

//防注入函数

function inject_check($sql_str){

$check = eregi('select|insert|update|delete|\*|\/\*|\'|\.\.\/|\.\/|UNION|into|load_file|outfile',$sql_str);

if($check){

page_href("http://".$_SERVER['HTTP_HOST']."/home/sitemap.php");

exit();

}else{

return $sql_str;

}

}

//防跨站攻击

function inject_check2($sql_str){

$check =

eregi('javascript|vbscript|expression|applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|

frameset|ilayer|layer

|bgsound|title|base|onabort|onact

ivate|onafterprint|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus

|onbeforepaste|onbeforeprint|onbeforeunload|onb

eforeupdate|onblur|onbounce|oncellchange|onchange|onclick|oncontextmenu|oncontrolselect|oncopy|oncut|

ondataavailable

|ondatasetchanged|ondatasetcomplete|ondblc

lick|ondeactivate|ondrag|ondragend|ondragenter|ondragleave|ondragover|ondragstart|

ondrop|onerror|onerrorupdate

|onfilterchange|onfinish|onfocus|onfocusin|onfoc

usout|onhelp|onkeydown|onkeypress|onkeyup|onlayoutcomplete|onload|onlosecapture

|onmousedown|onmouseenter|

onmouseleave|onmousemove|onmouseout|onmouseover|onmou

seup|onmousewheel|onmove|onmoveend|onmovestart|onpaste|onpropertychange|onreadystatechange|onreset|

onresize|onresizeend|onresizestart|onrowenter|onrowexit|onr

owsdelete|onrowsinserted|onscroll|onselect|onselectionchange|onselectstart|onstart|onstop|

onsubmit|onunload',$sql_str);

if($check){

page_href("http://".$_SERVER['HTTP_HOST']."/home/sitemap.php");

exit();

}else{

//return $sql_str;

}

} //by www.jbxue.com

?>

您可能感兴趣的文章:

PHP安全过滤代码(360提供 安全系数高)

PHP过滤post,get敏感数据的实例代码

php 过滤非法与特殊字符串的方法

php 防注入的一段代码(过滤参数)

php正则过滤html标签、空格、换行符等的代码示例

php实现过滤IP黑白名单的方法

很好用的php防止sql注入漏洞过滤函数的代码

php防止sql注入正则过滤一例

一段php过滤危险html的代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值