Hi,
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,
Hi,
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,
This has been answered in another Q: http://stackoverflow.com/questions/173851/what-is-the-canonical-way-to-determine-commandline-vs-http-execution-of-a-php-s
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());
}
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.