1

I have a php script which I want to run only from the command prompt, and want it to be blocked over HTTP. How should I do it?

What I have tried:

define('CLI_SCRIPT', true);

It did not help me a lot, was still able to open the file.

Adding to .htaccess:

DENY FROM ALL

It blocks the file from all source, even from the command prompt.

I cannot place it outside the public_html. I don't have access to other folders of the server.

1
  • 3
    "It blocks the file from all source, even from the command prompt." Uh, no, that's not possible, unless you're doing something like curl http://example.com/script.php, in which case you should just be doing php script.php.
    – ceejayoz
    Commented Jan 13, 2015 at 5:18

1 Answer 1

4

You can use the function php_sapi_name to exit early if the return value is not "cli".

if (php_sapi_name() !== "cli") {
    exit();
}
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.