2018年7月26日 星期四

php 取得請求的方法

class G {

    public $NOW_TIME;
    public $REQUEST_METHOD;
    public $IS_GET;
    public $IS_POST;
    public $IS_PUT;
    public $IS_DELETE;
    public $IS_AJAX;

    public function __construct() {
        $this->NOW_TIME = $_SERVER['REQUEST_TIME'];
        $this->REQUEST_METHOD = $_SERVER['REQUEST_METHOD'];
        $this->IS_GET = ($this->REQUEST_METHOD == 'GET' ? true : false);
        $this->IS_POST = ($this->REQUEST_METHOD == 'POST' ? true : false);
        $this->IS_PUT = ($this->REQUEST_METHOD == 'PUT' ? true : false);
        $this->IS_DELETE = ($this->REQUEST_METHOD == 'DELETE' ? true : false);

        $ajax_var = 'ajax';
        $postAjax = isset($_POST[$ajax_var]) && $_POST[$ajax_var] == 1 ? true : false;
        $getAjax = isset($_POST[$ajax_var]) && $_POST[$ajax_var] == 1 ? true : false;
        $commonAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false;


        $this->IS_AJAX = ($commonAjax || $postAjax || $getAjax) ? true : false;

        }

}