PHP security considerations

Source: Internet
Author: User

 

User-submitted data

The major weakness of many PHP programs is not the problem of the PHP language, but caused by the low security awareness of programmers. Therefore, you must always pay attention to the possible problems in each piece of code to find out the possible impact of incorrect data submission.

 

Example 30-1. Dangerous variable usage

 

<? Php

// Delete an object from the user directory, or ...... Can I delete more items?

Unlink ($ evil_var );

 

// Record user login, or ...... Can I add data in/etc/passwd?

Fwrite ($ fp, $ evil_var );

 

// Execute some common commands, or ...... You can execute rm-rf *?

System ($ evil_var );

Exec ($ evil_var );

 

?> Always pay attention to your code to ensure that all the variables submitted from the client are properly checked and then ask yourself the following questions:

Can this script only affect the expected files?

 

Can an abnormal data be used after it is submitted?

 

Can this script be used for unplanned purposes?

 

Can this script be combined with other scripts to do bad things?

 

Are all transactions fully recorded?

 

Ask yourself these questions when writing code. Otherwise, you may need to rewrite the Code to increase security. If you pay attention to these problems, you may not be able to guarantee the security of the system, but at least you can improve the security.

You can also consider disabling register_globals, magic_quotes, or other settings that make programming more convenient but make the legitimacy of a variable, and the sources and values of the variable messy. During development, you can use the error_reporting (E_ALL) mode to check whether the variables have been checked or initialized before they are used, so as to prevent some abnormal data from being scratched.

 

 

From Hurry's column

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: 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.