<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 驗證碼輔助函數 驗證碼輔助函數文件包含了一些幫助你創建驗證碼圖片的函數。 [TOC=2,3] ## [加載輔助函數](http://codeigniter.org.cn/user_guide/helpers/captcha_helper.html#id6) 該輔助函數通過下面的代碼加載: ~~~ $this->load->helper('captcha'); ~~~ ## [使用驗證碼輔助函數](http://codeigniter.org.cn/user_guide/helpers/captcha_helper.html#id7) 輔助函數加載之后你可以像下面這樣生成一個驗證碼圖片: ~~~ $vals = array( 'word' => 'Random word', 'img_path' => './captcha/', 'img_url' => 'http://example.com/captcha/', 'font_path' => './path/to/fonts/texb.ttf', 'img_width' => '150', 'img_height' => 30, 'expiration' => 7200, 'word_length' => 8, 'font_size' => 16, 'img_id' => 'Imageid', 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', // White background and border, black text and red grid 'colors' => array( 'background' => array(255, 255, 255), 'border' => array(255, 255, 255), 'text' => array(0, 0, 0), 'grid' => array(255, 40, 40) ) ); $cap = create_captcha($vals); echo $cap['image']; ~~~ * 驗證碼輔助函數需要使用 GD 圖像庫。 * 只有?**img_path**?和?**img_url**?這兩個參數是必須的。 * 如果沒有提供?**word**?參數,該函數將生成一個隨機的 ASCII 字符串。 你也可以使用自己的詞庫,從里面隨機挑選。 * 如果你不設置 TRUE TYPE 字體(譯者注:是主要的三種計算機矢量字體之一)的路徑,將使用 GD 默認的字體。 * "captcha" 目錄必須是可寫的。 * **expiration**?參數表示驗證碼圖片在刪除之前將保留多久(單位為秒),默認保留 2 小時。 * **word_length**?默認值為 8,?**pool**?默認值為 '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' * **font_size**?默認值為 16,GD 庫的字體對大小有限制,如果字體大小需要更大一點的話可以設置一種 TRUE TYPE 字體。 * **img_id**?將會設置為驗證碼圖片的 "id" 。 * **colors**?數組中如果有某個顏色未設置,將使用默認顏色。 ### [添加到數據庫](http://codeigniter.org.cn/user_guide/helpers/captcha_helper.html#id8) 使用驗證碼函數是為了防止用戶胡亂提交,要做到這一點,你需要將?create_captcha()?函數返回的信息保存到數據庫中。 然后,等用戶提交表單數據時,通過數據庫中保存的數據進行驗證,并確保它沒有過期。 這里是數據表的一個例子: ~~~ CREATE TABLE captcha ( captcha_id bigint(13) unsigned NOT NULL auto_increment, captcha_time int(10) unsigned NOT NULL, ip_address varchar(45) NOT NULL, word varchar(20) NOT NULL, PRIMARY KEY `captcha_id` (`captcha_id`), KEY `word` (`word`) ); ~~~ 這里是使用數據庫的示例。在顯示驗證碼的那個頁面,你的代碼類似于下面這樣: ~~~ $this->load->helper('captcha'); $vals = array( 'img_path' => './captcha/', 'img_url' => 'http://example.com/captcha/' ); $cap = create_captcha($vals); $data = array( 'captcha_time' => $cap['time'], 'ip_address' => $this->input->ip_address(), 'word' => $cap['word'] ); $query = $this->db->insert_string('captcha', $data); $this->db->query($query); echo 'Submit the word you see below:'; echo $cap['image']; echo '<input type="text" name="captcha" value="" />'; ~~~ 然后在處理用戶提交的頁面,處理如下: ~~~ // First, delete old captchas $expiration = time() - 7200; // Two hour limit $this->db->where('captcha_time < ', $expiration) ->delete('captcha'); // Then see if a captcha exists: $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?'; $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); $query = $this->db->query($sql, $binds); $row = $query->row(); if ($row->count == 0) { echo 'You must submit the word that appears in the image.'; } ~~~ ## [可用函數](http://codeigniter.org.cn/user_guide/helpers/captcha_helper.html#id9) 該輔助函數有下列可用函數: create_captcha([$data = ''[,?$img_path = ''[,?$img_url = ''[,?$font_path = '']]]]) 參數: * **$data**?(array) -- Array of data for the CAPTCHA * **$img_path**?(string) -- Path to create the image in * **$img_url**?(string) -- URL to the CAPTCHA image folder * **$font_path**?(string) -- Server path to font 返回: array('word' => $word, 'time' => $now, 'image' => $img) 返回類型: array 根據你提供的一系列參數生成一張驗證碼圖片,返回包含此圖片信息的數組。 ~~~ array( 'image' => IMAGE TAG 'time' => TIMESTAMP (in microtime) 'word' => CAPTCHA WORD ) ~~~ **image**?就是一個 image 標簽: ~~~ <img src="http://example.com/captcha/12345.jpg" width="140" height="50" /> ~~~ **time**?是一個毫秒級的時間戳,作為圖片的文件名(不帶擴展名)。就像這樣:1139612155.3422 **word**?是驗證碼圖片中的文字,如果在函數的參數中沒有指定 word 參數,這將是一個隨機字符串。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看