Home  >  Article  >  Backend Development  >  Detailed explanation of php protocol

Detailed explanation of php protocol

php中世界最好的语言
php中世界最好的语言Original
2017-12-20 19:26:463921browse

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



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);//读取


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

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=65f1762588797cc7d73b2de1d2ea6442 This parameter is required. It specifies the data stream you want to filter.

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

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

a3283853e6890ab963ef12d7dc0da257 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;])
?>

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!

Statement:
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
Previous article:How to use AjaxNext article:How to use Ajax