Codeigniter captcha

captcha 是現在防止機器人最常用的一種防止方式,而且現在很多都有提供class可以使用,本篇將實作cool-php-captchaCaptcha Numbers V2.1這二套captcha,並且使用的是Codeigniter framework

.htaccess

將_images目錄排除rewrite

1
2
3
RewriteEngine on
RewriteCond $1 !^(index.php|_images|_css|_js|robots.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

cool-php-captcha

1. 下載 cool-php-captcha-0.3.zip
2. 解壓縮放置_images目錄下
3. 在view檔案裡面放置captcha images

1
<img src="<?=base_url()?>_images/cool-php-captcha-0.3/captcha.php">

Captcha Numbers V2.1

1. 下載 captchanumbersv21-2006-03-07.zip
2. 解壓縮放置_images目錄下
3. 新增fonts目錄並將arial.ttf字型檔放入
4. 在view檔案裡面放置captcha images

1
<img src="<?=base_url()?>_images/captchanumbersv21/example.php">

驗證 captcha

1
2
3
if (strtolower(trim($_REQUEST['captcha'])) != $_SESSION['captcha']) {
    return "Invalid captcha";
}

參考資料

Related Posts with Thumbnails

相關文章

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>