Php web website development security

Source: Internet
Author: User

Php web website development security
Php is an easy-to-use and easy-to-use computer programming language. I didn't know much about php security at work, and I have written some programs: the data submitted at the front end is not escaped (html tags such as <and> are not converted into html entities). During the test, the user input content is displayed as html tag format, which is very embarrassing, shame is a trivial matter. What is important is that the security of the program is not guaranteed. I have read a very simple interview question in the past: http://www.phpstar.cn/?category=php To obtain the value of the category parameter. The question is very simple. I believe that php users can make category worthwhile. For example, $ _ GET ['category '] can be written by many people. In this way, the value cannot be obtained, it does not have to be processed securely. The following is an example of php security: 1. Use of include. <? Php include $ action. '. php';?> Among them, the $ action variable may come from the get method outside. It seems that there is no problem, but if $ action =' http://www.baidu.com/error ? So here we need to add a judgment: Does the file to be introduced exist? Php if (file_exists ($ action. '. php') {include $ action.'. php' ;}?> 2. Run xss across sites: for example, in a comment box, enter <script type = "text/javascript"> alert ('It blog! '); </Script> If the program does not directly display the information, think about what will happen? A pop-up window is displayed in front of the user's "IT blog !". 3. SQL Injection <? Php $ SQL = "SELECT * FROM user WHERE username = '{$ username}' AND passw = '{$ passw}'"; $ result = mysql_query ($ SQL);?> Assume that the value obtained by $ username is admin 'or '1 = 1, and $ passw is also like this: passw' or '1 = 1, and the preceding SQL statement becomes <? Php $ SQL = "SELECT * FROM user WHERE username = 'admin' or '1 = 1' AND passw = 'passw 'or '1 = 1 '"; $ result = mysql_query ($ SQL);?> The method to reduce such insecure programming is simple: intval is used to process the data transmitted from the user end, And htmlspecialhtmlspecialchars is used for the string.

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: info-contact@alibabacloud.com 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.