Summary of protocols and encapsulation protocols supported by php (recommended) and php Encapsulation
Preface
The development technology of today's web programs is truly a battle, ASP. NET, PHP, JSP, Perl, AJAX, and so on. Regardless of the future development of Web technology, it is important to understand the basic protocols for communication between Web applications because they allow us to understand the internal work of Web applications.
PHP has many built-in URL-style encapsulation protocols and can be used for file system functions like fopen (), copy (), file_exists (), and filesize. In addition to these encapsulation protocols, you can also use stream_wrapper_register () to register custom encapsulation protocols.
Note: The URL syntax used to describe an encapsulation protocol only supports the syntax of scheme. Scheme:/and scheme: the syntax is not supported.
Php protocol type
- File: //-access the local file system
- Http: //-access the HTTP (s) URL
- Ftp: //-access FTP (s) URLs
- Php: //-access each input/output stream (I/O streams)
- Zlib: //-compressed stream
- Data: //-data (RFC 2397)
- Glob: //-find the matching file path Mode
- Phar: //-PHP Archive
- Ssh2: //-Secure Shell 2
- Rar: //-RAR
- Ogg: //-audio stream
- CT: //-Process Interactive streams
PHP. ini
- Allow_url_fopen: on is enabled by default. This option is on, which activates the URL-based fopen encapsulation protocol to allow access to URL object files.
- Allow_url_include: off is disabled by default. If this option is set to on, the URL object files can be included.
File: // Protocol
File: //-access the local file system, which is not affected by allow_url_fopen and allow_url_include.
Usage
File: // [absolute file path and file name]
http://127.0.0.1/code/1.php?file=file:///E:\phpStudy\WWW\code\phpinfo.php
Php: // Protocol
Php: //-access each input/output stream (I/O streams)
You do not 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 the corresponding input or output stream of the PHP process.
Php: // stdin is read-only, and php: // stdout and php: // stderr are only written.
Php: // stdin
<? Php while ($ line = fopen ('php: // stdin ', 'R') {// open our file pointer to read from stdin echo $ line. "\ n"; echo fgets ($ line); // read}?>
Php: // stdout
<?php $fd = fopen('php://stdout', 'w'); if ($fd) { echo $fd."\n"; fwrite($fd, "test"); fwrite($fd, "\n"); fclose($fd); }?>
Php: // stderr
<?php $stderr = fopen( 'php://stderr', 'w' ); echo $stderr."\n"; fwrite($stderr, "uknow" ); fclose($stderr);?>
Php: // filter
The most commonly used pseudo protocol can be used to read arbitrary files.
Php: // filter is a metadatabase that is designed for filtering applications when data streams are opened. This is very useful for all-in-one file functions, such as readfile (), file (), and file_get_contents (). Other filters are not used before reading data streams.
Parameters
| Name |
Description |
| Resource = <data stream to be filtered> |
This parameter is required. It specifies the data stream you want to filter. |
| Read = <read chain filtering list> |
This parameter is optional. You can set one or more filter names separated by pipe characters. |
| Write = <write link filtering list> |
This parameter is optional. You can set one or more filter names separated by pipe characters. |
| <; Filtering list of two chains> |
Any Filter list without a prefix of read = or write = will be applied to the read or write chain as needed. |
<?phpinclude($_GET['file'])?>
http://127.0.0.1/code/1.php?file=php://filter/read=convert.base64-encode/resource=./phpinfo.php
Php: // input
Php: // input can access the read-only stream of the requested raw data and execute the data in the post request as PHP code.
- Allow_url_fopen: off/on
- Allow_url_include: on
Zip: //, bzip2: //, zlib: // Protocol
Zip: //, bzip2: //, zlib: // The protocol can also be used properly under double off conditions;
Zip: //, bzip2: //, zlib: // all belong to the compressed stream. You can access the subfiles In the compressed file. More importantly, you do not need to specify the suffix.
- Allow_url_fopen: off/on
- Allow_url_include: off/on
Usage
Zip: // archive.zip # dir/file.txt
Zip: // [absolute path of the compressed file] # [subfile name in the compressed file]
Test
Upload the file after the upload. Other compression formats can also be used.
Because # subsequent parameters will be ignored in the get request, the url encoding should be % 23 when using the get request, and the relative path tested here is not feasible, therefore, only absolute paths can be used.
http://127.0.0.1/code/1.php?file=zip://E:\phpStudy\WWW\code/1.zip%231.txt
Data: // Protocol
Data: // the Protocol must be on for normal use;
- Allow_url_fopen: on
- Allow_url_include: on
http://127.0.0.1/code/1.php?file=data://text/plain,<?php phpinfo()?>http://127.0.0.1/code/1.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=
Glob: // Protocol
Glob: //-find the matching file path Mode
<?php$it = new DirectoryIterator($_GET['file']);foreach($it as $f) { printf("%s", $f->getFilename());echo'</br>'; }?>
CT: // Protocol
CT: //-Process Interactive streams
This encapsulation protocol is disabled by default.
To use the keep CT: // package, you must install the» keep CT extension on» PECL.
Usage
expect://command
Appendix: differences between the stateless HTTP protocol and Connection: keep-alive
Stateless means that the Protocol has no memory for transaction processing, and the server does not know the client status. On the other hand, there is no connection between opening a webpage on a server and the webpage on the server you opened before.
HTTP is a stateless connection-oriented protocol. Stateless does not mean that HTTP cannot maintain a TCP connection, nor does it mean that HTTP uses a UDP Protocol (No connection)
Starting from HTTP/1.1, Keep-Alive is enabled by default to maintain the connection feature. To put it simply, after a webpage is opened, the TCP connection between the client and the server for transmitting HTTP data will not be closed. If the client accesses the webpage on the server again, it will continue to use this established connection.
Keep-Alive does not Keep the connection permanently. It has a retention time, which can be set in different server software (such as Apache ).
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.
Reference
- PHP
- Php pseudo-protocol implements seven commands