What is the method for getting HTTP request in php

王林
Release: 2023-03-02 11:02:02
forward
3461 people have browsed it

What is the method for getting HTTP request in php

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;
Copy after login

What is the method for getting HTTP request in php

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

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template