Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make php page disabled from browser

Tags:

php

I'm writing a PHP script that I want to disable from web access (I will ask users to move it out of the web root and execute via CLI, but you never know if they'll listen!)

Is there a simple function that occurs to anyone to make the page die if it's requested by a browser?

Thanks for any ideas.

like image 992
julio Avatar asked Mar 21 '26 19:03

julio


1 Answers

You could test whether the script is being run through the CLI using php_sapi_name().

It can return a whole bunch of different possible values when run on a HTTP server - difficult to make a reliable distinction there - but there seems to be only one possible return value for the CLI: cli.

If you're looking for an all-purpose solution, make sure you read the comment thread below for more detailed discussion on some potential gotchas.

like image 179
Pekka Avatar answered Mar 23 '26 09:03

Pekka