开发者

check the source of a file

开发者 https://www.devze.com 2023-01-17 07:29 出处:网络
i want php code to open a file and search in it for some dangerous words like if(preg_match(\"/(echo|zend|print|print_r|phpinfo|

i want php code to open a file and search in it for some dangerous words like

if(preg_match("/(echo|zend|print|print_r|phpinfo|
symlink|ini_set|telnet|cgi|
eval|bas开发者_运维问答e64_encode|base64_decode)/iU",$filesource)){
echo 'error';
}

how i can make it


If you want to parse PHP code, use token_get_all to get an array of language tokens.


pretty much like you outlined :)

But have you looked at tools like phpcs and phpcpd?

You can open up any php file like a regular text file and parse through it without including it in your script.

<?php
$filedata = file_get_contents('/path/to/file.php');
if (preg_match('/foo/', $filedata) {
    echo "file contained 'foo'\n";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消