PHPCMS v9 自定義表單添加驗證碼驗證


1、  在 \phpcms\templates\default\formguide\show.html 中添加驗證碼顯示

    <input type="text" id="code" name="code" size="8" class="input-text">{form::checkcode('code_img', '4', '14', 84, 24)}

2、 在 \phpcms\modules\formguide\index.php 中修改

    具體如下

<?php
defined('IN_PHPCMS') or exit('No permission resources.');
define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
  $session_storage = 'session_'.pc_base::load_config('system','session_storage');   //判斷驗證碼
  pc_base::load_sys_class($session_storage);    //判斷驗證碼
class index {


 private $db, $m_db, $M;
 function __construct() {
  $this->db = pc_base::load_model('sitemodel_model');
  $this->m_db = pc_base::load_model('sitemodel_field_model');
  $this->M = new_html_special_chars(getcache('formguide', 'commons'));
  $this->siteid = get_siteid();
  $this->M = $this->M[$this->siteid];    

 

找到下面代碼

   if (isset($_POST['dosubmit'])) {

        $tablename = 'form_'.$r['tablename'];
         $this->m_db->change_table($tablename);

   在下方加入:

   if(!empty($_SESSION['code'])) {
    //判斷驗證碼
    $code = isset($_POST['code']) && trim($_POST['code']) ? trim($_POST['code']) : showmessage(L('input_code'), HTTP_REFERER);
    if ($_SESSION['code'] != strtolower($code)) {
     showmessage(L('code_error'), HTTP_REFERER);
    }
   }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM