顯示具有 CodeIgniter 標籤的文章。 顯示所有文章
顯示具有 CodeIgniter 標籤的文章。 顯示所有文章

星期三, 7月 04, 2012

「PHP CI」Form Validation

關於CI的單表驗證
網站介紹的很詳細:http://codeigniter.com/user_guide/libraries/form_validation.html


1.建立規則


$config=array(  //設定驗證規則
         array(
         'field'=>'name',  //input的name
         'label'=>'帳號',     //設定名稱,在輸出錯誤訊息時出現的名稱
         'rules'=>'trim|required|min_length[4]|max_length[23]|xss_clean'  //驗證使用的規則
           ),
         array(
          'field'=>'passwd',
          'label'=>'密碼',
          'rules'=>'required|min_length[4]|max_length[25]|md5'
           ),  


2.設定規則
$this->CI->form_validation->set_rules($config);  
3.頁面POST回傳是否正確
$this->CI->form_validation->run()

他提供相當多的驗證規則,相當方便,可以少寫很多CODE。



星期五, 3月 02, 2012

「archLinux」 Postfix 使用 Gmail smtp

最近需要用到 MailServer ,以前也沒有這個經驗,
純粹是PHP smpt 寄信速度的問題,最後選擇了 postfix。
文章參考
  1. http://sherlock.heroku.com/blog/2012/02/03/setting-up-postfix-to-use-gmail-as-an-smtp-relay-host-in-archlinux/ 
  2. archLinux WIki Postfix
「安裝 postfix」

    #pacman -S postfix

「設定」在 /etc/postfix/main.cf   加入

    # 設定 gmail
    relayhost = [smtp.gmail.com]:587

    # 啟用 tls 認證
    smtp_use_tls=yes

    # use sasl when authenticating to foreign SMTP servers
    smtp_sasl_auth_enable = yes

    # 設定密碼路徑
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

    # list of CAs to trust when verifying server certificate
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

    # eliminates default security options which are incompatible with gmail
    smtp_sasl_security_options =

 「建立」在 /etc/postfix/sasl_passwd  (即密碼檔案路徑)

     [smtp.gmail.com]:587  username:password

 「執行」建立資料庫檔案

    # postmap /etc/postfix/sasl_passwd

 「啟動服務」

    # rc.d start postfix

 「CodeIgniter」 使用 Email 類別

    $this->load->library('email');

    $config['protocol'] = 'sendmail';

    $config['mailpath'] = '/usr/sbin/sendmail';

    $config['charset'] = 'UTF-8';

    $this->email->initialize($config);