PHP Security Considerations

Source: Internet
Author: User

User-Submitted data

Many PHP programs have a major weakness is not the PHP language itself, but the programmer's security awareness is not high. Therefore, you must always be aware of the possible problems with each piece of code to discover the possible impact of incorrect data submissions.

Example 30-1. Dangerous variable Usage <?php

Delete a file from the user directory, or ... Can delete more things?

Unlink ($evil _var);

Log the user's login, or ... Can I add data to/etc/passwd?

Fwrite ($fp, $evil _var);

Execute some common commands, or ... Can execute RM-RF *?

System ($evil _var);

EXEC ($evil _var);

?> must always keep an eye on your code to ensure that every variable submitted from the client is properly checked, and then ask yourself the following questions:

Does this script affect only the files that you expect?

Can the abnormal data be brought into effect after being submitted?

Can this script be used for unplanned purposes?

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

Have all the transactions been fully documented?

Ask yourself these questions when you write your code, or you might want to rewrite the code later to add security. Paying attention to these problems may not be enough to keep the system safe, but at least it can improve security. You can also consider turning off register_globals,magic_quotes or other settings that make programming easier but will make a variable more legitimate, the source, and its value being messed up. At development time, you can use the error_reporting (e_all) mode to help check whether a variable is checked or initialized before it is used, which prevents some unhealthy data from being scratched.

PHP Security Considerations

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.