11##############
2- CAPTCHA Helper
2+ CAPTCHA 輔助函式
33##############
44
5- The CAPTCHA Helper file contains functions that assist in creating
6- CAPTCHA images.
5+ CAPTCHA 輔助函式包含了各種輔助產生驗證圖片的相關函數。
76
87.. contents ::
98 :local:
@@ -12,17 +11,19 @@ CAPTCHA images.
1211
1312 <div class =" custom-index container" ></div >
1413
15- Loading this Helper
14+ 導入輔助函式
1615===================
1716
18- This helper is loaded using the following code::
17+ CAPTCHA 輔助函式的載入語法如下:
18+ ::
1919
2020 $this->load->helper('captcha');
2121
22- Using the CAPTCHA helper
22+ 使用 CAPTCHA 輔助函式
2323========================
2424
25- Once loaded you can generate a CAPTCHA like this::
25+ 準備好如下所示的語法後,就可以產生驗證碼:
26+ ::
2627
2728 $vals = array(
2829 'word' => 'Random word',
@@ -49,32 +50,24 @@ Once loaded you can generate a CAPTCHA like this::
4950 $cap = create_captcha($vals);
5051 echo $cap['image'];
5152
52- - The captcha function requires the GD image library.
53- - Only the **img_path ** and **img_url ** are required.
54- - If a **word ** is not supplied, the function will generate a random
55- ASCII string. You might put together your own word library that you
56- can draw randomly from.
57- - If you do not specify a path to a TRUE TYPE font, the native ugly GD
58- font will be used.
59- - The "captcha" directory must be writable
60- - The **expiration ** (in seconds) signifies how long an image will remain
61- in the captcha folder before it will be deleted. The default is two
62- hours.
63- - **word_length ** defaults to 8, **pool ** defaults to '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
64- - **font_size ** defaults to 16, the native GD font has a size limit. Specify a "true type" font for bigger sizes.
65- - The **img_id ** will be set as the "id" of the captcha image.
66- - If any of the **colors ** values is missing, it will be replaced by the default.
67-
68- Adding a Database
53+ - 驗證碼函式需要 GD 圖像函式庫。
54+ - 只有 **img_path ** 與 **img_url ** 是必填的。
55+ - 假設沒有填 **word **,函式會自動生成一個隨機的 ASCII 字串,當然你也可以從你自己準備的文字庫當中隨機挑選。
56+ - 如果你沒有標明字型檔的路徑,將會使用醜醜的預設字型。
57+ - “captcha” 資料夾必須是可以寫入的。
58+ - **expiration ** (以秒數計) 標明出驗證碼圖示過多久之後會被刪除,預設是兩小時。
59+ - **word_length ** 預設為 8,**pool ** 預設為 ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’。
60+ - **font_size ** 預設為 16,GD 字型有大小限制。如果要使用更大的字體請選用其他字型。
61+ - **img_id ** 將是驗證碼圖示的 id。
62+ - 如果任一 **colors ** 內的值不見了,將會以預設值代替。
63+
64+ 建立驗證碼資料庫
6965-----------------
7066
71- In order for the captcha function to prevent someone from submitting,
72- you will need to add the information returned from ``create_captcha() ``
73- to your database. Then, when the data from the form is submitted by
74- the user you will need to verify that the data exists in the database
75- and has not expired.
67+ 為了避免驗證碼被有心人士利用,你可以將 ``create_captcha() `` 所回傳的資訊加入到資料庫中。如此一來,當資料從使用者端送來的時候只需要驗證此筆資料是否存在且未過期即可。
7668
77- Here is a table prototype::
69+ 資料表建置範例
70+ ::
7871
7972 CREATE TABLE captcha (
8073 captcha_id bigint(13) unsigned NOT NULL auto_increment,
@@ -85,8 +78,8 @@ Here is a table prototype::
8578 KEY `word` (`word`)
8679 );
8780
88- Here is an example of usage with a database. On the page where the
89- CAPTCHA will be shown you'll have something like this ::
81+ 這是搭配資料庫使用的範例語法。在頁面中驗證碼顯示的地方,你可以填入如下的語法:
82+ ::
9083
9184 $this->load->helper('captcha');
9285 $vals = array(
@@ -108,15 +101,15 @@ CAPTCHA will be shown you'll have something like this::
108101 echo $cap['image'];
109102 echo '<input type="text" name="captcha" value="" />';
110103
111- Then, on the page that accepts the submission you'll have something like
112- this ::
104+ 然後,資料接收端頁面則填入如下語法:
105+ ::
113106
114- // First, delete old captchas
107+ // 首先,刪除舊的驗證碼
115108 $expiration = time() - 7200; // Two hour limit
116109 $this->db->where('captcha_time < ', $expiration)
117110 ->delete('captcha');
118111
119- // Then see if a captcha exists:
112+ // 確認驗證碼是否存在
120113 $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?';
121114 $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
122115 $query = $this->db->query($sql, $binds);
@@ -127,23 +120,21 @@ this::
127120 echo 'You must submit the word that appears in the image.';
128121 }
129122
130- Available Functions
123+ 可用函數格式
131124===================
132125
133- The following functions are available:
126+ 允許使用的函數格式如下:
134127
135128.. php :function :: create_captcha([$data = ''[, $img_path = ''[, $img_url = ''[, $font_path = '']]]])
136129
137- :param array $data: Array of data for the CAPTCHA
138- :param string $img_path: Path to create the image in
139- :param string $img_url: URL to the CAPTCHA image folder
140- :param string $font_path: Server path to font
130+ :param array $data: 存有驗證碼資訊的陣列
131+ :param string $img_path: 建立驗證碼圖示的路徑
132+ :param string $img_url: 驗證碼圖示資料夾的 URL
133+ :param string $font_path: 字型檔的伺服器路徑
141134 :returns: array('word' => $word, 'time' => $now, 'image' => $img)
142- :rtype: array
135+ :rtype: 陣列
143136
144- Takes an array of information to generate the CAPTCHA as input and
145- creates the image to your specifications, returning an array of
146- associative data about the image.
137+ 取得輸入在陣列中的資訊生成驗證碼,且根據你的需求產生驗證碼圖示,並將圖示的相關資訊回傳。
147138
148139 ::
149140
@@ -153,12 +144,11 @@ The following functions are available:
153144 'word' => CAPTCHA WORD
154145 )
155146
156- The **image ** is the actual image tag::
147+ 回傳的 **image ** 是 HTML 圖示標籤:
148+ ::
157149
158150 <img src="http://example.com/captcha/12345.jpg" width="140" height="50" />
159151
160- The **time ** is the micro timestamp used as the image name without the
161- file extension. It will be a number like this: 1139612155.3422
152+ 回傳的 **time ** 是被用來當作圖片檔名(沒有副檔名)的時間戳記,就像是這樣的數字:1139612155.3422
162153
163- The **word ** is the word that appears in the captcha image, which if not
164- supplied to the function, will be a random string.
154+ 回傳的 **word ** 是出現在驗證碼圖示中的文字,如果沒有指定特定字串給函式的話將會隨機挑選一個字串。
0 commit comments