不知道這和館長看到的內容有沒有很像?我沒讀完全文,不敢發表評論。還是提醒一下 AI 摘要與重點可能會有各種狀況產生錯誤與誤解的地方,和新聞媒體不同的地方是,新聞亂報有人負責,有法可據,如果你把 AI 生成的東西當作你的東西,你就要承受 AI 出錯的代價,如果明知如此卻又故意隱瞞,就有欺騙的嫌疑了,請三思。
在 CodeIgniter 4 開發中,為了提升專案的可維護性,遵守檔案命名規範與 use 語句的正確性是非常重要的。然而,手動檢查這些細節可能耗時且容易出錯。為了解決這個問題,我開發了一款 Sublime Text 外掛,專門用於自動檢查 CodeIgniter 4 專案的命名規範和 use 語句。
在這篇文章中,我將介紹這個外掛的功能、使用方式、注意事項,以及如何對其進行客製化修改。
外掛功能(截至 2024-12-13)
這個外掛的主要功能是檢查 PHP 檔案是否符合 CodeIgniter 4 的命名規範和 use 語句的使用規則:
在 is_codeigniter4_project 方法中,你可以自訂需要檢查的目錄結構: def is_codeigniter4_project(self, directory): required_paths = ["app", "writable"] optional_paths = ["public", "vendor"] for path in required_paths: if not os.path.isdir(os.path.join(directory, path)): return False if not any(os.path.isdir(os.path.join(directory, path)) for path in optional_paths): return False return True
// This is the demo secret key. In production, we recommend
// you store your secret key(s) safely.
const SECRET_KEY = "1x0000000000000000000000000000000AA";
async function handlePost(request) {
const body = await request.formData();
// Turnstile injects a token in "cf-turnstile-response".
const token = body.get("cf-turnstile-response");
const ip = request.headers.get("CF-Connecting-IP");
// Validate the token by calling the
// "/siteverify" API endpoint.
let formData = new FormData();
formData.append("secret", SECRET_KEY);
formData.append("response", token);
formData.append("remoteip", ip);
const url = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
const result = await fetch(url, {
body: formData,
method: "POST",
});
const outcome = await result.json();
if (outcome.success) {
// ...
}
}
此步驟確保 token 是有效的,且未被重複使用,防止重放攻擊。
4. 從 Google reCAPTCHA 遷移
如果你目前使用的是 Google reCAPTCHA,可以使用 Turnstile 的兼容模式,修改載入腳本:
...
#Directory protection rules
include /PATH_AUTH_BASIC/auth_basic.conf;
#PHP reference configuration
include PHP-73.conf;
#REWRITE-START URL rewrite rule reference, any modification will invalidate the rewrite rules set by the panel
include /PATH_REWRITE/rewrite.conf;
...