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★