- 1、本文档共11页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 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
您可能关注的文档
- imba(IMBA).doc
- id 32 staph 葡萄球菌的鉴定系统(ID 32 Staph staphylococcal identification system).doc
- iis无法安装(IIS cannot install).doc
- idata_一部别具特色的词典_评_易混同音近音词解析词典_王芳智(Idata_ is a unique _ rating _ dictionary easy mixed words dictionary _ homophone analytic Wang Fangzhi).doc
- internet 的影响(the internet 的影响).doc
- ioc与di(ioc与di).doc
- inter应用 考试大纲_考试大纲_上海市干部培训中心(The application of inter _ syllabus syllabus _ Shanghai cadres training center).doc
- ipad2你不可不知的26个使用小技巧(Ipad2 you must not know the 26 little tricks used).doc
- ipad使用技巧(IPad usage skills).doc
- ipad2和ipad有什么区别和不同(What are the differences and differences between ipad2 and iPad).doc
- [临汾]2024年山西临汾市曲沃县公立医院招聘32人笔试上岸历年典型考题与考点剖析附带答案详解.docx
- 教科版四年级科学下册7.电路中的开关教学设计.docx
- 人音版三年级下册第3单元 《我们的朋友》大单元课时.docx
- [丽水]2024年浙江丽水青田县招聘专职社区工作者51人笔试上岸历年典型考题与考点剖析附带答案详解.docx
- 【新课标】Module 3 Unit 2 Period 3 The ant and the grasshopper 教案(含作业设计).docx
- [嘉兴]浙江嘉兴市职工技术协会招聘工作人员笔试上岸历年典型考题与考点剖析附带答案详解.docx
- 人美版(主编常锐伦、欧京海)二年级美术上册6.下雨了教学设计.docx
- [南京]2024年江苏南京师范大学附属中学招聘教师18人笔试上岸历年典型考题与考点剖析附带答案详解.docx
- [宁波]浙大宁波理工学院招聘事业编制体育教师4人笔试上岸历年典型考题与考点剖析附带答案详解.docx
- [宿州]2024年安徽宿州泗县引进县外在编在职教师40人笔试上岸历年典型考题与考点剖析附带答案详解.docx
文档评论(0)