This article describes the method of determining whether PHP custom functions are submitted by Get, Post and Ajax. Share it for your reference, as follows:
/** * Is it submitted by AJAx * @return bool */ function isAjax(){ if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ return true; }else{ return false; } } /** * Is it submitted by GET */ function isGet(){ return $_SERVER['REQUEST_METHOD'] == 'GET' ? true : false; } /** * Is it a POST submission * @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; }
For more information about PHP related content, please check out the topic of this site:Summary of PHP network programming skills》、《Summary of the usage of php curl》、《Complete collection of PHP array (Array) operation techniques》、《Summary of usage of php strings》、《PHP data structure and algorithm tutorial》、《Summary of PHP Programming Algorithm"and"Summary of common database operation techniques for php》
I hope this article will be helpful to everyone's PHP programming.