How PHP gets HTTP requests

Time:2020-11-25

Method of getting HTTP request by PHP

$5 Introduction to server

$5 Server is an array of information such as header, path, and script locations.

Sample method for getting HTTP request


$req_method = $_SERVER['REQUEST_METHOD'];
echo $req_method;

Examples supplement:

Socket mode

Using socket to establish connection, splicing HTTP message to send data for HTTP request.

An example of get mode:


<?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);
}
?>

PHP to this article about how PHP get HTTP requests on this, more relevant PHP get HTTP request method content, please search the previous articles of developeppaer or continue to browse the related articles below, I hope you can support developeppaer more in the future!