- Determine the request type
$_SERVER[‘REQUEST_METHOD’]
Stored in this variable is the method of form submission
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <code><span> $method </span> =<span> $_SERVER </span>[<span> 'REQUEST_METHOD' </span>];
<span> $data </span> = <span> '' </span>;
<span> if </span> (<span> $method </span> == <span> 'GET' </span>)
{
<span> $data </span> = <span> $_SERVER </span>[<span> 'QUERY_STRING' </span>];
}
<span> else </span><span> if </span> (<span> $method </span> == <span> 'POST' </span>)
{
<span> $data </span> = file_get_contents (<span> "php://input" </span>);
}
<span> else </span>
{
<span> $logger </span>-><span>error</span>(<span> 'unknown http method. url: ' </span> . <span> $_SERVER </span>[<span> 'REQUEST_URI' </span>]);
}</code>
|
Copy after login
1 2 3 4 5 6 7 8 9 10 11 | <code><span>
<span>
<span> echo </span><span> 'http://' </span>.<span> $_SERVER </span>[<span> 'HTTP_HOST' </span>].<span> $_SERVER </span>[<span> 'PHP_SELF' </span>].<span> '?' </span>.<span> $_SERVER </span>[<span> 'QUERY_STRING' </span>];
<span>
<span>
<span> echo </span> dirname(<span> $url </span>);</code>
|
Copy after login
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above introduces how PHP handles http post/get requests, including aspects of the process. I hope it will be helpful to friends who are interested in PHP tutorials.