Home  >  Article  >  Backend Development  >  PHP custom function to determine which submission method is used

PHP custom function to determine which submission method is used

小云云
小云云Original
2018-02-01 10:09:561759browse

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自定义函数调用和执行过程详解

The above is the detailed content of PHP custom function to determine which submission method is used. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn