You could use php_sapi_name().
See this demo lifted from the developer docs
<?php
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Your are probably a human";
} else {
echo "You are probably not a human";
}
?>
You could just apply this kind of conditional at the start of your script.