反机器人图标Captcha插件 jQuery和PHP IconCaptcha

  • 源码大小:417.5KB
  • 所需积分:1积分
  • 源码编号:19JP-3108
  • 浏览次数:645次
  • 最后更新:2023年05月06日
  • 所属栏目:表单
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

IconCapcha是一个简单、灵活、可定制、用户友好、基于jQuery和PHP的captcha插件,用于防止网络应用程序上的垃圾邮件和机器人程序。

主要特点:

  • 使用PHP进行服务器端验证。
  • 浅色和深色主题。
  • AJAX加载。
  • 自定义反馈消息。
  • 有用的事件。
  • 一个页面上有多个实例。
  • 像素完美的图标。
  • 跨浏览器。

如何使用它:

1.在html文档中加载jQuery库和Icon Captcha插件的文件。

  1. <!-- jQuery is OPTIONAL -->
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3.  
  4. <!-- IconCaptcha Files -->
  5. <link href="/css/icon-captcha.min.css" rel="stylesheet">
  6. <script src="/js/icon-captcha.min.js"></script>

2.在HTML表单中添加一个图标captcha占位符。

  1. <form method="post">
  2. <!-- Additional security token to prevent CSRF. Optional but highly recommended - disable via IconCaptcha options. -->
  3. <input type="hidden" name="_iconcaptcha-token" value="<?= IconCaptcha::token() ?>"/>
  4. <!-- The IconCaptcha will be rendered in this element -->
  5. <div class="iconcaptcha-holder" data-theme="light"></div>
  6. </form>

3.调用函数在表单元素内生成一个图标captcha。

  1. // Vanilla JS
  2. document.addEventListener('DOMContentLoaded', function() {
  3. IconCaptcha.init('.iconcaptcha-holder', {
  4. // options here
  5. });
  6. });
  7.  
  8. // jQuery
  9. $(document).ready(function() {
  10. $('.iconcaptcha-holder').iconCaptcha({
  11. // options here
  12. })
  13. });

4.自定义captcha图标的默认选项。

  1. $('.iconcaptcha-holder').iconCaptcha({
  2. general: {
  3. // path to captcha-request.php
  4. validationPath: null,
  5. fontFamily: null,
  6. // show, hide or disable the credits element of the captcha
  7. // show, hide or disabled
  8. credits: 'show',
  9. },
  10. security: {
  11. clickDelay: 1500,
  12. hoverDetection: true,
  13. enableInitialMessage: true,
  14. initializeDelay: 500,
  15. selectionResetDelay: 3000,
  16. loadingAnimationDelay: 1000,
  17. invalidateTime: 1000 * 60 * 2,
  18. },
  19. messages: {
  20. initialization: {
  21. loading: 'Loading challenge...',
  22. verify: 'Verify that you are human.'
  23. },
  24. header: 'Select the image displayed the <u>least</u> amount of times',
  25. correct: 'Verification complete.',
  26. incorrect: {
  27. title: 'Uh oh.',
  28. subtitle: "You've selected the wrong image."
  29. },
  30. timeout: {
  31. title: 'Please wait 60 sec.',
  32. subtitle: 'You made too many incorrect selections.'
  33. }
  34. }
  35. })

5.可用的事件处理程序。

  1. $('.example').iconCaptcha()
  2. .on('init', function(e, id) {
  3. // Event: Captcha initialized
  4. }).on('selected', function(e, id) {
  5. // Event: Icon selected
  6. }).on('refreshed', function(e, id) {
  7. // Event: Captcha refreshed
  8. }).on('success', function(e, id) {
  9. // Event: Correct input
  10. }).on('error', function(e, id) {
  11. // Event: Wrong input
  12. }).on('invalidated', function(e, id) {
  13. // Event: Wrong input
  14. }).on('timeout', function(e, id) {
  15. // Event: Wrong input
  16. });

更新日志:

2023-04-04

  • 第3.1.2版

预览截图