之前看過使用sfCaptchaGDPlugin插件的文章。。按照上面的步驟下來。貌似還是不行。
這裡我使用的是symfony1.4,把我正常情況下的步驟放上來,大家分享一下。
1.首先去下載下傳sfCaptchaGDPlugin
2.啟用插件,要在ProjectConfiguration.class.php裡面添加上
- class ProjectConfiguration extends sfProjectConfiguration {
- public function setup() {
- $this->enablePlugins('sfDoctrinePlugin');
- $this->enablePlugins('sfDoctrineGuardPlugin');
- $this->enablePlugins('sfDoctrineActAsSignablePlugin');
- $this->enablePlugins('sfCaptchaGDPlugin');
- }
- }
3.在你要使用的app裡面啟用插件。。修改settings.yml
- all:
- .settings:
- # Form security secret (CSRF protection)
- csrf_secret: db498ea94181dc9c289cac99a1e665488bf7daed
- enabled_modules: [default, sfGuardGroup, sfGuardUser, sfGuardPermission,sfGuardAuth,sfCaptchaGD]
- # Output escaping settings
- escaping_strategy: true
- escaping_method: ESC_SPECIALCHARS
- # Enable the database manager
- use_database: true
- # sfDoctrinePlugin插件設定登入登出動作
- login_module: sfGuardAuth
- login_action: signin
- # ecNote sfDoctrinePlugin插件設定認證控制動作
- secure_module: sfGuardAuth
- secure_action: secure
- standard_helpers: [Partial, Cache, I18N]
- i18n: true
4.可以在APP.YML裡面配置一些插件。
- all:
- sf_captchagd:
- p_w_picpath_width: 100 # 驗證碼圖檔的寬度(px)
- p_w_picpath_height: 30 # 驗證碼圖檔的高度(px)
- chars: "123456789abc" # 驗證碼中會出現的字元
- length: 4 # 驗證碼長度
- font_size: 18 # 字型大小
- force_new_captcha: false # if true - captcha regenerated EVERY request, even if user input true value before
- # possible chars colors
- font_color: ["252525", "8b8787", "550707", "3526E6", "88531E"] #字型色
- # chars fonts
- fonts: ["akbar/akbar.ttf", "brushcut/BRUSHCUT.TTF", "molten/molten.ttf", "planet_benson/Planetbe.ttf", "whoobub/WHOOBUB_.TTF"] #字型
- background_color: DDDDDD # 驗證碼的背景色
- border_color: 000000 # 驗證碼的邊框色
5.增加一條插件的路由,routing.yml
- sf_captchagd:
- url: /administrator/captcha/:key/:reload
- param: { module: sfCaptchaGD, action: getImage, key: failed, reload: 0 }
6. 修改插件的權限控制,把插件的通路權限關掉。
plugins/sfCaptchaGDPlugin/modules/sfCaptchaGD/
在這個目錄下新增config檔案夾,并添加security.yml檔案。
- default:
- is_secure: false
7.確定你的系統的extension=php_gd2.dll是開啟的。
8.接着CC一下我們的項目
- class sfGuardFormSignin extends BasesfGuardFormSignin
- {
- /**
- * @see sfForm
- */
- public function configure()
- {
- $this->widgetSchema['captcha'] = new sfWidgetCaptchaGD();
- $this->validatorSchema['captcha'] = new sfCaptchaGDValidator(array('length' => 4),array('required'=>'驗證碼為必填項!','invalid'=>'驗證碼錯誤!','length'=>'請輸入4位驗證碼!'));
- $this->widgetSchema['captcha']->setLabel('驗證碼');
- }
- }