How can you use the $_SERVER superglobal array to differentiate between a web page request and a command line script execution in PHP?
To differentiate between a web page request and a command line script execution in PHP, you can check the value of the 'REQUEST_METHOD' key in the $_SERVER superglobal array. If the 'REQUEST_METHOD' key is set to 'GET' or 'POST', it indicates a web page request. If it is not set or is empty, it indicates a command line script execution.
if (isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST')) {
echo 'Web page request';
} else {
echo 'Command line script execution';
}