关于php中sql注射的有关问题

WBOY
Release: 2016-06-13 10:03:08
Original
861 people have browsed it

关于php中sql注射的问题
我自己做了个小论坛,偶然发现了可以注射比如:http://localhost/BBS/detail.php?articalID=4

目的是:显示文章ID为4的帖子,我现在在后面加上这样一句话就遍了样:http://localhost/BBS/detail.php?articalID=4 or 1=1,返回的结果是所有的帖子都显示出来了,后来我在网上看到了这样一个函数:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function safe($string){return "'" . MySQL_real_escape_string( $string ) . "'";}
Copy after login

,结果使用了自定义函数之后报错了,这个MySQL_real_escape_string能给个详细的用法吗?

怎么防止注射?

------解决方案--------------------
PHP code
function safe($string=null){ return addslashes($string);}<br><font color="#e78608">------解决方案--------------------</font><br>一般来说,外部(POST,GET)获取的整数类型的值使用前加 intval()转换,字符串类型的加上 mysql_real_escape_string()过滤就可以了。<br><br>推荐一篇相关的文档,IBM网站上的:<br>确保 PHP 应用程序的安全 不能违反的四条安全规则<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!