Get it through $_SERVER.
(Recommended tutorial: php tutorial)
Introduction:
$_SERVER is a server that contains information such as header and path , and an array of information such as script locations.
Code example:
$req_method = $_SERVER['REQUEST_METHOD']; echo $req_method;
Supplement:
socket method
Use socket to establish connection and splice HTTP Messages are sent to make HTTP requests.
An example of GET method:
<?php $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?>
The above is the detailed content of What is the method for getting HTTP request in php. For more information, please follow other related articles on the PHP Chinese website!