Home > Backend Development > PHP Tutorial > Detailed explanation of php protocol

Detailed explanation of php protocol

php中世界最好的语言
Release: 2023-03-18 07:52:01
Original
3965 people have browsed it

We know that today’s WEB program development technology is full of contention, but no matter how WEB technology develops in the future, the basic communication protocol for WEB program quality inspection is very important. Today I will introduce to you the WEB application. Inner Workings

PHP comes with many built-in URL-style wrapper protocols for file systems# like fopen(), copy(), file_exists() and filesize() ##function. In addition to these packaging protocols, custom packaging protocols can also be registered through stream_wrapper_register().

Note: The URL syntax used to describe an encapsulated protocol only supports scheme://... syntax. scheme:/ and scheme: syntax are not supported.

php protocol type

file:// — Access local file system

http:// —Access HTTP(s) URL

ftp:// — Access FTP(s) URLs

php:// — Access individual input/output streams (I/O streams)

zlib:// — Compressed streams

data:// — Data (RFC 2397)

glob:// — Finds matching file path pattern

phar:// — PHP Archive

ssh2:// — Secure Shell 2

rar:// — RAR

ogg:// — Audio Streaming

expect:// - Process interactive streams

PHP.ini

allow_url_fopen: on By default, this option is turned on to activate the fopen encapsulation protocol in the form of a URL, making it accessible URL object files, etc.

allow_url_include: off is turned off by default. If this option is on, it allows the inclusion of URL object files, etc.

file:// protocol

file:// — access the local file system , not affected by allow_url_fopen and allow_url_include


Usage method

file:// [absolute path and file name of the file]

   
http://127.0.0.1/code/1.php?file=file:///E:\phpStudy\WWW\code\phpinfo.php
Copy after login



php://protocol

php:// — Access various input/output streams (I/O streams)

There is no need to enable allow_url_fopen, only php://input, php://stdin, php://memory and php://temp need to enable allow_url_include.

php://stdin, php://stdout and php://stderr

php://stdin, php://stdout and php://stderr allow direct access to PHP The corresponding input or output stream of the process.

php://stdin is read-only, php://stdout and php://stderr are write-only.

php://stdin

<?php
 while($line = fopen(&#39;php://stdin&#39;,&#39;r&#39;))
 {//open our file pointer to read from stdin
 echo $line."\n";
 echo fgets($line);//读取
Copy after login


<?php
 $fd = fopen(&#39;php://stdout&#39;, &#39;w&#39;);
 if ($fd) {
 echo $fd."\n";
 fwrite($fd, "test");
 fwrite($fd, "\n");
 fclose($fd);
 }
?>
Copy after login
<?php
 $stderr = fopen( &#39;php://stderr&#39;, &#39;w&#39; );
 echo $stderr."\n";
 fwrite($stderr, "uknow" );
 fclose($stderr);
?>
Copy after login

The most commonly used pseudo-protocol, which can generally be used to read any file.

php://filter is a meta-wrapper designed for filtering applications when a data stream is opened. This is useful for all-in-one file functions like readfile(), file() and

file_get_contents(), where there is no opportunity to apply additional filters before the data stream contents are read.


resource= This parameter is required. It specifies the data stream you want to filter.

read= This parameter is optional. One or more filter names can be set, separated by pipe characters.

write= This parameter is optional. One or more filter names can be set, separated by pipe characters. ​

Any filter list not prefixed with read= or write= will be applied to the read or write chain as appropriate.

<?php
    include($_GET[&#39;file&#39;])
?>
Copy after login

http://127.0.0.1/code/1.php?file=php://filter/read=convert.base64-encode/resource=./phpinfo.php


I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

PHP large traffic optimization?

PHP product flash sale timing implementation (solution to large traffic)

How PHP solves the problem of large website traffic and high concurrency

The above is the detailed content of Detailed explanation of php protocol. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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