PHP web page protection SQL injection method configuration

Source: Internet
Author: User
Tags sql injection methods
The precondition is that we need to have the server management permission, that is, we can modify php. ini file. next I will introduce how to modify the php configuration file to prevent SQL injection methods. For more information, see. to ensure security, you can open quot; php. ini... the precondition is that we need to have the server management permission, that is, we can modify php. ini file. next I will introduce how to modify the php configuration file to prevent SQL injection methods. For more information, see.

For security, you can open "php. ini "file security mode, set" safe_mode = On "; if the" display_erros "option that displays PHP execution error information is enabled, a lot of available information will be returned to intruders, therefore, you need to set it to "display_erros = off"; in this way, the information after the PHP function execution error will not be displayed in the browser of the client.

In addition, there is an important configuration option in the file. if you set the "magic_quotes_gpc" item to "On ", the PHP program automatically converts the variables submitted by the user into escape characters containing the backslash. this option is similar to parameter filtering in the ASP program, most injection attacks can be prevented.

A program is very good. if you do not have the server management permission, you can use the following code:

 | <| = | In | like) |/*. +? */|
 
  
$ Value) {$ this-> stopattack ($ key, $ value, $ this-> getfilter);} foreach ($ _ POST as $ key => $ value) {$ this-> stopattack ($ key, $ value, $ this-> postfilter);} foreach ($ _ COOKIE as $ key => $ value) {$ this-> stopattack ($ key, $ value, $ this-> cookiefilter) ;}/ *** check the parameter and write the log */public function stopattack ($ StrFiltKey, $ StrFiltValue, $ ArrFiltReq) {if (is_array ($ StrFiltValue) $ StrFiltValue = implode ($ StrFiltV Alue); if (preg_match ("/". $ ArrFiltReq. "/is", $ StrFiltValue) = 1) {$ this-> writeslog ($ _ SERVER ["REMOTE_ADDR"]. "". strftime ("% Y-% m-% d % H: % M: % S "). "". $ _ SERVER ["PHP_SELF"]. "". $ _ SERVER ["REQUEST_METHOD"]. "". $ StrFiltKey. "". $ StrFiltValue); showmsg ('The parameter you submitted is invalid. The system has recorded your operation! ', '', 0, 1) ;}/ *** SQL injection log */public function writeslog ($ log) {$ log_path = CACHE_PATH. 'logs '. DIRECTORY_SEPARATOR. 'SQL _log.txt'; $ ts = fopen ($ log_path, "a +"); fputs ($ ts, $ log. "rn"); fclose ($ ts );}}
 


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.