php中如何防范sql注入(How to prevent SQL injection in PHP).doc

php中如何防范sql注入(How to prevent SQL injection in PHP).doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
php中如何防范sql注入(How to prevent SQL injection in PHP)

php中如何防范sql注入(How to prevent SQL injection in PHP) How to prevent SQL injection in PHP In PHP coding, if you take into account some of the more basic security issues, first of all: 1. initialize your variables If ($admin) { Echo login successful! ; Include (admin.php); } Else { Echo you are not an administrator and cannot be managed! ; } Well, we see that the above code seems to work properly. No problem, so join me and submit an illegal parameter. How about the effect? For our page is /login.php, then we submit: /login.php? Admin=1, oh, you want to, we are not directly is the administrator, direct management. Of course, we could not have made such a mistake simply wrong, so some hidden errors may also cause this problem, such as the recent storms out of the phpwind 1.3.6 forum is a loophole, which can directly get administrator privileges, because there is a $skin variable is not initialized, lead to a series of problems behind. So how do we avoid the above problems? First of all, starting with php.ini, the register_global = off in php.ini, that is, not all registered variables are global, can be avoided. But we are not server administrators and can only be improved from code, so how can we improve the code above? Lets rewrite as follows: $admin = 0; / / initialize variables if ($_ post _ [admin] $_ use post _ pass [admin]) { / / / / / / / / / / / / / / 判断提交的管理员用户名和密码是不是对的相应的处理代码 / / / / / / / / / / / / / /. admin = $1. } else { admin = $0; } if (admin) { echo 登陆成功.; include (admin.php). } else { echo 你不是管理员, 无法进行管理.; } 那么这时候你再提交 http: / / / login.php? admin = 1 就不好使了, $因为我们在一开始就把变量初始化为 admin = 0 了, 那么你就无法通过这个漏洞获取管理员权限. 2. 防止sql injection (sql注射) sql 注射应该是目前程序危害最大的了, 包括最早从asp到php, 基本上都是国内这两年流行的技术, 基本原理就是通过对提交变量的不过滤形成注入点然后使恶意用户能够提交一些sql查询语句, 导致重要数据被窃取、数据丢失或者损坏, 或者被入侵到后台管理. 那么我们如何去防范呢? 这个就应该我们从代码去入手了. 我们知道web上提交数据有两种方式, 一种是get、一种是post, 那么很多常见的sql注射就是从get方式入手的, 而且注射的语句里面一定是包含一些sql语句的, 因为没有sql语句, 那么如何进行, sql语句有四大句. Select, update, delete, insert, so can we avoid the

您可能关注的文档

文档评论(0)

jgx3536 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:6111134150000003

1亿VIP精品文档

相关文档