check the source of a file
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";
}
精彩评论