Determine whether a user source is a get or post based on the HTTP header

Source: Internet
Author: User

OSC looked at someone asked how to tell whether the user is get or post, here to make a note

The HTTP header has a request Method that indicates whether the requests are get or post

Put a code on the YII code

Returns the method of the current request, keeping in mind that the method name is case sensitive and should be converted by specification to uppercase public function GetMethod () {    //$this->methodparam default value ' _method '    If $_post[' _method ' is specified, the request is used to impersonate another method using a POST request.    //$_post[' _method ' at this time is the type of request being simulated.    if (isset ($_post[$this->methodparam])) {        return strtoupper ($_post[$this->methodparam]);    Or use the value of $_server[' Http_x_http_method_override '] as the method name.    } elseif (Isset ($_server[' http_x_http_method_override ')) {        return strtoupper ($_server[' http_x_http_ Method_override ']);    or use $_server[' Request_method '] as the method name, not specified, default to GET method    } else {        return isset ($_server[' Request_method '])? C11/>strtoupper ($_server[' Request_method '): ' GET ';    }}

This method uses 3 methods to obtain the current user's request, the priority from high to low is:

    • When using a POST request to impersonate another request, use $_post[' _method '] As the method of the current request;
    • Otherwise, if there is a x_http_method_override HTTP header, the method specified by the HTTP header is used as the request method, as X-http-method-override: put indicates that the request is to be executed by the Put method;
    • If the x_http_method_override does not exist, the request_method Value as the method of the current request. If the even request_method does not exist, the request is considered a GET request.

The previous two methods were designed primarily for user agents that only support limited methods such as Get and post.


Determine whether a user source is a get or post based on the HTTP header

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.