Home > Article > Backend Development > PHP determines whether there is a get submission
本文实例讲述了PHP自定义函数判断是否为Get、Post及Ajax提交的方法。
分享给大家供大家参考,具体如下: (推荐学习:PHP视频教程)
/** * 是否是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; }
The above is the detailed content of PHP determines whether there is a get submission. For more information, please follow other related articles on the PHP Chinese website!