Questions about SQL injection in PHP

Source: Internet
Author: User
Questions about SQL injection in PHP
I made a little forum myself, and I stumbled across a shot that could be injected. For example: http://localhost/BBS/detail.php?articalID=4

The goal is: to display the article ID 4 post, I now add such a sentence after the sample: Http://localhost/BBS/detail.php?articalID=4 or 1=1, returned the result is all the posts are displayed, Then I saw a function on the Internet:
PHP Code
  function Safe ($string) {return "'". Mysql_real_escape_string ($string). "'";}

, the result of using a custom function after the error, this mysql_real_escape_string can give a detailed usage?

How to prevent injections?

PHP Code
function Safe ($string =null) {return addslashes ($string);}
Generally, the value of the integer type obtained by the external (post,get) is used before the intval () conversion, and the string type plus the mysql_real_escape_string () filter is available.

Recommend a related document on the IBM website:
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.