久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

不推薦使用常量 FILTER_SANITIZE_STRING

Constant FILTER_SANITIZE_STRING is deprecated(不推薦使用常量 FILTER_SANITIZE_STRING)
本文介紹了不推薦使用常量 FILTER_SANITIZE_STRING的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我已經安裝了 PHP 8.1 并開始測試我的舊項目.我使用了過濾器 FILTER_SANITIZE_STRING 像這樣:

I have installed PHP 8.1 and I started testing my old project. I have used the filter FILTER_SANITIZE_STRING like so:

$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);

現在我收到此錯誤:

已棄用:不推薦使用常量 FILTER_SANITIZE_STRING

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated

當我使用 FILTER_SANITIZE_STRIPPED 時也會發生同樣的情況:

The same happens when I use FILTER_SANITIZE_STRIPPED:

已棄用:不推薦使用常量 FILTER_SANITIZE_STRIPPED

Deprecated: Constant FILTER_SANITIZE_STRIPPED is deprecated

我可以用什么代替它?

推薦答案

這是一個用途可疑的過濾器.很難說它究竟要完成什么任務或何時應該使用它.由于其名稱,它也與默認字符串過濾器混淆,而實際上默認字符串過濾器稱為 FILTER_UNSAFE_RAW.PHP 社區決定不再支持使用此過濾器.

This was a filter of dubious purpose. It's difficult to say what it was meant to accomplish exactly or when it should be used. It was also confused with the default string filter, due to its name, when in reality the default string filter is called FILTER_UNSAFE_RAW. The PHP community decided that the usage of this filter should not be supported anymore.

此過濾器的行為非常不直觀.它刪除了 < 和字符串結尾之間或直到下一個 > 之間的所有內容.它還刪除了所有 NUL 字節.最后,它將 '" 編碼到它們的 HTML 實體中.

The behaviour of this filter was very unintuitive. It removed everything between < and the end of the string or until the next >. It also removed all NUL bytes. Finally, it encoded ' and " into their HTML entities.

如果你想更換它,你有幾個選擇:

If you want to replace it, you have a couple of options:

  1. 使用不進行任何過濾的默認字符串過濾器 FILTER_UNSAFE_RAW.如果您對 FILTER_SANITIZE_STRING 的行為一無所知,而您只想使用一個默認過濾器來為您提供字符串值,則應該使用它.

  1. Use the default string filter FILTER_UNSAFE_RAW that doesn't do any filtering. This should be used if you had no idea about the behaviour of FILTER_SANITIZE_STRING and you just want to use a default filter that will give you the string value.

如果您使用此過濾器來防御 XSS 漏洞,請將其替換為 htmlspecialchars().不要在輸入數據上調用此函數.為了防止 XSS,您需要對輸出進行編碼!

If you used this filter to protect against XSS vulnerabilities, then replace its usage with htmlspecialchars(). Don't call this function on the input data. To protect against XSS you need to encode the output!

如果您確切地知道該過濾器的作用并且想要創建一個 polyfill,則可以使用正則表達式輕松完成.

If you knew exactly what that filter does and you want to create a polyfill, you can do that easily with regex.

function filter_string_polyfill(string $string): string
{
    $str = preg_replace('/x00|<[^>]*>?/', '', $string);
    return str_replace(["'", '"'], ['&#39;', '&#34;'], $str);
}

這篇關于不推薦使用常量 FILTER_SANITIZE_STRING的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 二区av| 国产免费色 | 97国产一区二区精品久久呦 | 韩国av一区二区 | 国产一区二区三区久久久久久久久 | 日韩视频精品 | 欧美精品中文字幕久久二区 | 国产亚洲精品久久19p | 二区高清 | 久久久在线视频 | 毛片免费看的 | 中文字幕亚洲欧美日韩在线不卡 | 欧美精品在线免费 | 综合九九 | 狠狠干网站| 91精品国产色综合久久不卡98 | 91资源在线 | 久久久久国产一区二区三区 | 久久福利电影 | 日韩一二区| 亚洲激情在线观看 | av性色全交蜜桃成熟时 | 国产精品久久久久久久久久久久午夜片 | www久久久 | 国产精品久久久久久久久久 | 成人在线播放网址 | 激情六月丁香婷婷 | 欧美日韩国产精品一区 | 国产高清精品一区二区三区 | 中文字幕三区 | 日日夜夜精品视频 | 中文字幕一区二区三区乱码图片 | 久久久久久亚洲国产精品 | 国产99精品 | 国产欧美精品一区二区色综合 | 视频国产一区 | 野狼在线社区2017入口 | 免费黄视频网站 | 亚洲国产一区二区视频 | 国产精品亚洲综合 | 国产成人精品久久二区二区91 |