php自定义函数如何判断是哪种提交方式呢?本文主要介绍了php自定义函数判断是否为get、post及ajax提交的方法,涉及php服务器预定义变量$_server及字符串相关操作技巧,需要的朋友可以参考下,希望能帮助到大家。
/**
* 是否是ajax提交的
* @return bool
*/
function isajax(){
if(isset($_server['http_x_requested_with']) && strtolower($_server['http_x_requested_with']) == 'xmlhttprequest'){
return true;
}else{
return false;
}
}
/**
* 是否是get提交的
*/
function isget(){
return $_server['request_method'] == 'get' ? true : false;
}
/**
* 是否是post提交
* @return int
*/
function ispost() {
return ($_server['request_method'] == 'post' && checkurlhash($globals['verify']) && (empty($_server['http_referer']) || preg_replace("~https?:\/\/([^\:\/]+).*~i", "\\1", $_server['http_referer']) == preg_replace("~([^\:]+).*~", "\\1", $_server['http_host']))) ? 1 : 0;
}
相关推荐:
js里内置函数和自定义函数怎么使用
php使用自定义函数实现统计中文字符串长度的方法实例详解
php自定义函数调用和执行过程详解
以上就是php自定义函数判断是哪种提交方式的详细内容。