From the PHP anti-SQL injection code provided in 360 to a class-PHP source code

Source: Internet
Author: User
A class changed from the PHP anti-SQL injection code provided in 360 A class changed from the PHP anti-SQL injection code provided in 360

When a website was searched by Baidu a few days ago, it prompts "security alliance reminds you: This website has security risks. please visit it with caution !", So I began to work hard to find a solution, and finally solved the problem from SQL injection and HTTP cross-site. here I will record it.

 | <| = | In | like) | \\/ \\ *. +? \ * \/| <\ S * script \ B | \ bEXEC \ B | UNION. +? SELECT | UPDATE. +? SET | INSERT \ s + INTO. +? VALUES | (SELECT | DELETE). +? FROM | (CREATE | ALTER | DROP | TRUNCATE) \ s + (TABLE | DATABASE) "; private $ postfilter =" \ B (and | or) \ B. {1, 6 }? (=|>|<|\\ Bin \ B |\\ blike \ B) |\\/ \\ *. +? \ * \/| <\ S * script \ B | \ bEXEC \ B | UNION. +? SELECT | UPDATE. +? SET | INSERT \ s + INTO. +? VALUES | (SELECT | DELETE). +? FROM | (CREATE | ALTER | DROP | TRUNCATE) \ s + (TABLE | DATABASE) "; private $ cookiefilter =" \ B (and | or) \ B. {1, 6 }? (=|>|<|\\ Bin \ B |\\ blike \ B) |\\/ \\ *. +? \ * \/| <\ S * script \ B | \ bEXEC \ B | UNION. +? SELECT | UPDATE. +? SET | INSERT \ s + INTO. +? VALUES | (SELECT | DELETE). +? FROM | (CREATE | ALTER | DROP | TRUNCATE) \ s + (TABLE | DATABASE) ";/*** constructor */public function _ construct () {foreach ($ _ GET as $ key = >$ 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 ($ StrFiltK Ey, $ StrFiltValue, $ ArrFiltReq) {if (is_array ($ StrFiltValue) $ StrFiltValue = implode ($ StrFiltValue); 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! ', '',) ;}/ *** 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. "\ r \ n"); fclose ($ ts) ;}}?>

The above is the content of a class changed from the PHP anti-SQL injection code provided by 360 to. For more information, see PHP Chinese website (www.php1.cn )!

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.