
內容簡介
Really Simple CAPTCHA 並不是獨立的外掛,而是設計可以與其他外掛一起使用的。它最初是為 Contact Form 7 設計製作的,但是您也可以使用它與您自己的外掛搭配使用。
注意:這個產品完全遵循其名稱 "Really Simple" 的設計,亦即,它不是非常安全的。如果您需要完美的安全性,您可以試試其他解決方案。
它是如何運作的?
Really Simple CAPTCHA 不使用 PHP 的「Sessions」來儲存狀態,是和其他 PHP CAPTCHA 解決方案不同的,但是使用臨時檔案來儲存狀態。這讓您可以將其嵌入 WordPress 中,而不用擔心可能出現的衝突。
當您要產生 CAPTCHA 時,Really Simple CAPTCHA 會為其創建兩個檔案;一個是 CAPTCHA 的圖像檔案,另一個是儲存正確答案的文字檔案。
這兩個檔案的檔名有相同(隨機)的前綴,例如 "a7hk3ux8p.png" 和 "a7hk3ux8p.txt"。在這種情況下,例如如果回答者將 "K5GF" 作為回答 "a7hk3ux8p.png" 圖像時,Really Simple CAPTCHA 會計算出 "K5GF" 的雜湊值,並與儲存在 "a7hk3ux8p.txt" 檔案中的雜湊值進行比對。如果兩者匹配,答案就被證實正確。
如何與您的外掛一起使用
注意:以下是提供給外掛開發人員的指示。
首先,創建一個 ReallySimpleCaptcha 類別的實例:
$captcha_instance = new ReallySimpleCaptcha();
您可以按照自己的意願更改實例變數。
// Change the background color of CAPTCHA image to black
$captcha_instance->bg = array( 0, 0, 0 );
如果您對其他變數感興趣,請查看 really-simple-captcha.php。
為 CAPTCHA 產生一個隨機單字。
$word = $captcha_instance->generate_random_word();
在臨時目錄中生成圖像檔案及相應的文字檔案。
$prefix = mt_rand();
$captcha_instance->generate_image( $prefix, $word );
然後展示圖像,並取得回答者的答案。
檢查答案的正確性。
$correct = $captcha_instance->check( $prefix, $the_answer_from_respondent );
如果 $correct 為 true,就進行後續處理。否則,封鎖回答者,因為它看起來似乎不是人類。
最後,請清除臨時圖像檔案和文字檔案,因為它們不再使用。
$captcha_instance->remove( $prefix );
就是這樣。
如果您想要看一個實際的範例,您可以試試 Contact Form 7。
外掛標籤
開發者團隊
原文外掛簡介
Really Simple CAPTCHA does not work alone and is intended to work with other plugins. It is originally created for Contact Form 7, however, you can use it with your own plugin.
Note: This product is “really simple” as its name suggests, i.e., it is not strongly secure. If you need perfect security, you should try other solutions.
How does it work?
Really Simple CAPTCHA does not use PHP “Sessions” for storing states, unlike many other PHP CAPTCHA solutions, but stores them as temporary files. This allows you to embed it into WordPress without worrying about conflicts.
When you generate a CAPTCHA, Really Simple CAPTCHA creates two files for it; one is an image file of CAPTCHA, and the other is a text file which stores the correct answer to the CAPTCHA.
The two files have the same (random) prefix in their file names, for example, “a7hk3ux8p.png” and “a7hk3ux8p.txt.” In this case, for example, when the respondent answers “K5GF” as an answer to the “a7hk3ux8p.png” image, then Really Simple CAPTCHA calculates hash of “K5GF” and tests it against the hash stored in the “a7hk3ux8p.txt” file. If the two match, the answer is confirmed as correct.
How to use with your plugin
Note: Below are instructions for plugin developers.
First, create an instance of ReallySimpleCaptcha class:
$captcha_instance = new ReallySimpleCaptcha();
You can change the instance variables as you wish.
// Change the background color of CAPTCHA image to black
$captcha_instance->bg = array( 0, 0, 0 );
See really-simple-captcha.php if you are interested in other variables.
Generate a random word for CAPTCHA.
$word = $captcha_instance->generate_random_word();
Generate an image file and a corresponding text file in the temporary directory.
$prefix = wp_rand();
$captcha_instance->generate_image( $prefix, $word );
Then, show the image and get an answer from respondent.
Check the correctness of the answer.
$correct = $captcha_instance->check( $prefix, $the_answer_from_respondent );
If the $correct is true, go ahead. Otherwise, block the respondent — as it would appear not to be human.
And last, remove the temporary image and text files, as they are no longer in use.
$captcha_instance->remove( $prefix );
That’s all.
If you wish to see a live sample of this, you can try Contact Form 7.
