問題描述

有什麼區別,應該使用哪一個?

我知道 wp_verify_nonce 檢查時間限制,check_admin_referer 我認為調用 wp_verify_nonce 以及檢查一個管理網址段,但我有點困惑我應該使用哪個和什麼時候。

謝謝你的清晰。

最佳解決方案

我以為 check_admin_referer 檢查了這個隨機數 (它確實調用 wp_verify_nonce 和引用 url),在挖掘到核心代碼之後,我意識到它沒有這樣做,認為這是一個我報告的錯誤,Ryan Boren 回答説:

Actually, if the nonce is valid the referrer should not be checked. The unreliability of referrers is one of the reasons that nonces are used. Nonces replace referrer checking entirely. The only time we check the referrer is when handling the -1 backward compatibility condition. -1 means that someone is not using nonces so we fall back to referrer checking. This usage is now very rare. check_admin_referer() is badly named now that it almost never does referrer checking. It would be better named something like check_nonce(), but we keep it as is for back compat and old times sake.

所以實際上沒有區別。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。