What would be the cleanest method to tell if PHP has been invoked via a POST for example and not from html (under a web broser)
Thanks,
What would be the cleanest method to tell if PHP has been invoked via a POST for example and not from html (under a web broser)
Thanks,
If I understand your question correctly, it's not about http vs. command line call, but rather browser vs. "non-browser" (e.g. via curl, wget etc) call. There's no way to check this, because wget etc are technically browsers, they just don't happen to have a GUI. You can try checking HTTP_USER_AGENT, but this is totally unreliable, because there's no way to enforce a client to identify itself correctly.
This has been answered in another Q: What is the canonical way to determine commandline vs. http execution of a PHP script?
function __get_started_from_cli_state()
{
return substr(php_sapi_name(), 0, 3) == 'cli';
}
function __get_started_from_cgi_state()
{
return substr(php_sapi_name(), 0, 3) == 'cgi';
}
function __get_started_from_browser_state()
{
return !(__get_started_from_cli_state() ||
__get_started_from_cgi_state());
}