PHP伪协议学习小结

php://

PHP 提供了一些杂项输入/输出(IO)流,允许访问 PHP 的输入输出流、标准输入输出和错误描述符, 内存中、磁盘备份的临时文件流以及可以操作其他读取写入文件资源的过滤器。(不明白啥子鬼意思)

一、php://stdin   php://stdout     php://stderr

官方文档:The CLI SAPI defines a few constants for I/O streams to make programming for the command line a bit easier.CLI SAPI定义了一些新的I/O内容,这些内容使的命令行调试程序变得更简单。。。应该是这个意思。。)

  1. php://stdin:相当于打开一个文件指针,可以从输入缓冲区读取输入。

(注意要通过命令行打开文件,如果用浏览器访问,输入缓冲区会一直有一个空值造成while永远为真,导致系统卡死)

然后根据官方文档的介绍,如果我们想进行单行输入流的读取,可以使用STDIN

  1. php://stdout:打开一个文件指针,进行文件写入

  1. php://stderr:打开一个指针进行文件写入。

(具体参考官方文档:http://php.net/manual/en/features.commandline.io-streams.php

 

Php://inputallow_url_includeon

(其中entype=”multipart/form-data”是指按照二进制流的形式传输数据)

要理解上面这段代码,要先明白file_get_contents()函数。在官方手册中file_get_contents()是用来将文件的内容读入到一个字符串中的首选方法,file_get_contents()的$filename参数不仅仅为文件路径,还可以是一个URL(伪协议)。

file_get_contents() 解析传入字符串发现是伪协议中的php://input,便读取了[POSTDATA]的数据保存为一个字符串。 既通过了验证。

 

Php://output

 

php://filter(一般可以利用进行任意文件读取)

 

读取了class.php的源文件。

使用介绍:php://filter表示使用协议类型,read=<读取数据链用到的过滤器名称>用/隔开。

如上:file=php://filter/read=convert.base64-encode/resource=class.php

Resource=class.php表示要读取的文件流是class.php文件。

Read=convert.base64-encode,使用了一个转换过滤器,将字符串按照base64编码。

 

关于过滤器:过滤器有很多种,有字符串过滤器、转换过滤器、压缩过滤器、加密过滤器

字符串过滤器:

      进行rot13转换

             string.toupper

     将字符全部大写

              string.tolower

     将字符全部小写

               string.strip_tags

转换过滤器

convert.base64-encode & convert.base64-decode

1、base64 编码解码

convert.base64-encode和convert.base64-decode使用这两个过滤器等同于分别用 base64_encode()和 base64_decode()函数处理所有的流数据。 convert.base64-encode支持以一个关联数组给出的参数。如果给出了line-length,base64 输出将被用 line-length个字符为长度而截成块。如果给出了* line-break-chars*,每块将被用给出的字符隔开。这些参数的效果和用 base64_encode()再加上 chunk_split()相同。

convert.quoted-printable-encode & convert.quoted-printable-decode

 

2、quoted-printable 编码解码

convert.quoted-printable-encode和 convert.quoted-printable-decode等同于用 quoted_printable_decode()函数处理所有的流数据。没有和* convert.quoted-printable-encode*相对应的函数。* convert.quoted-printable-encode*支持以一个关联数组给出的参数。除了支持和 convert.base64-encode一样的附加参数外,* convert.quoted-printable-encode*还支持布尔参数 binary和 force-encode-first。 convert.base64-decode只支持 line-break-chars参数作为从编码载荷中剥离的类型提示。

 

这里只写了php://形式的伪协议,php官方文档中还有很多种伪协议,建议参考学习:http://php.net/manual/zh/wrappers.php

 

 

猜你喜欢

转载自blog.csdn.net/CSDNPM250/article/details/88712692
今日推荐