Monday, 12 August 2013

Checking PHP Syntax via Web Page

Checking PHP Syntax via Web Page

I've used "php -l" many times while on the command line to check whether a
file contains valid PHP, but I've struggled to perform this task from a
web page.
$out = `php -l /path/to/my.php`;
// or...
$out = `php -d error_reporting=1 -l /path/to/my.php`;
// or...
$out = `php -d error_reporting=1 -l /path/to/my.php 2>&1`;
print $out;
But nothing seems to return a value that I can test. I've tried using exec
and shell but nothing seems to return a value when it's called this way;
the same code works fine when PHP is called in CLI mode.
(For the record, authorized users are supplying these files, and I am
sanitizing the file input, and in this situation the check has to be done
via a web page).
Is there a way to do this?

No comments:

Post a Comment