Detailed explanation of the method of PHP custom function to determine whether it is submitted by Get/Post/Ajax

墨辰丷
Release: 2023-03-26 17:58:02
Original
1485 people have browsed it

这篇文章主要介绍了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;
}
Copy after login


相关推荐:

PHP自定义函数判断是否为Get、Post及Ajax提交的方法

jQuery自定义函数应用以及解析

关于php自定义函数及内部函数讲解

The above is the detailed content of Detailed explanation of the method of PHP custom function to determine whether it is submitted by Get/Post/Ajax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!