PHP中filter協議詳解

來源:互聯網
上載者:User
本文主要和大家分享PHP中filter協議詳解,希望能協助到大家。

php:// — 訪問各個輸入/輸出流(I/O streams)php://input 是個可以訪問請求的未經處理資料的唯讀流。php://filter 是一種設計用來允許過濾器程式在開啟時成為流的封裝協議。這對於單獨具有完整功能的檔案函數非常有用,否則就沒有機會在讀取內容之前將過濾器應用於流之上。該協議文法為:php://filter:/<action>=<name>比如 php://filter:/resource=http://www.baidu.com

使用 php://filter 擷取網頁內容:

<?php$url = 'http://www.phpfamily.cn';$data = file_get_contents('php://filter/resource=' . $url);echo $data;  //輸出結果我http://www.phpfamily.cn頁面的內容

php://filter 的 參數列表

參數 功能
read 讀取
write 寫入
resource 資料來源

read參數值可為

string.strip_tags: 將資料流中的所有html標籤清除
string.toupper: 將資料流中的內容轉換為大寫
string.tolower: 將資料流中的內容轉換為小寫
convert.base64-encode: 將資料流中的內容轉換為base64編碼 convert.base64-decode: 與上面對應解碼為典型的檔案包含漏洞。我們可以通過構造含有漏洞的語句,查看想要看的代碼: file=php://filter/convert.base64-encode/resource=index.php 。再將得到的base64碼解碼即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.