定制 dominiquevienne/honeypot 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dominiquevienne/honeypot

Composer 安装命令:

composer require dominiquevienne/honeypot

包简介

This PHP library is used to manage honeypots in HTML forms. It will create the input form and do the necessary checks.

README 文档

README

This PHP library is used to manage honeypots in HTML forms. It will create the input form and do the necessary checks.

Installation

Recommended

Go to you project root directory and use composer using this command

composer require dominiquevienne/honeypot

Then create your application bootstrap using this kind of code

<?php
require __DIR__ . '/vendor/autoload.php';

$oForm  = new Dominiquevienne\Honeypot\Form();
echo $oForm->inputs();

Manual installation

  • Download latest stable release on Github
  • Uncompress the downloaded file
  • Place content into your project
  • Use similar code to load object
<?php
require __DIR__ . '/honeypot/src/Honeypot.php';
require __DIR__ . '/honeypot/src/Form.php';

$oForm  = new Dominiquevienne\Honeypot\Form();
echo $oForm->inputs();

Laravel

Using honeypot in Laravel is as simple as a

composer require dominiquevienne/honeypot

and add the following lines in your class

<?php
use \Dominiquevienne\Honeypot\Form;

class yourController {
  public function show() {
    /** some code of yours */
    $oForm  = new Form();
    return $oForm->inputs();
  }
}

Drupal 8

First of all, go to your root directory of your Drupal 8 project and type

composer require dominiquevienne/honeypot

In the Form controller (where you build your form), add

use Dominiquevienne\Honeypot\Form;

in order to gain access to Honeypot Form constructor.

Instantiate your form using the drupalForm config array key set to TRUE

Checks are done in the validate function using standard functions.

How it works

Once the package is installed the honeypot consists in enabling two steps

Form rendering

Where you will trigger Form::timeCheck() which will store date-time of the Form rendering and trigger Form::honeypotInput() used to return the honeypot form element.

Any of those two options are mandatory.

<?php
$oForm          = new Dominiquevienne\Honeypot\Form();
$oForm->timeCheck();
$honeypotInputs = $oForm->inputs();
?>
<html>
<?php 
// All your HTML code before your form
?>
<form action="yourLandingPage.php" method="post">
<?php
// The standard fields of your form
echo $honeypotInputs;
?>
<input type="submit"/>
</html>

Be aware that you'll need to hide the honeypot field. To do that, you'll have three solutions

  • use CSS (default class is hide)
  • remove the element from the DOM using JS (Pure Javascript, jQuery or other). This is already done by using default function $oForm->inputs() or by using $oForm->getHoneypotScript() which would return a script in pure javascript that would remove the honeypot field from the DOM.

Form action page

Before you do the real job in your script of the landing page of your form (action attribute of Form element), you will have to use this code

<?php
$oHoneypot  = new Dominiquevienne\Honeypot\Honeypot();
$checks     = $oHoneypot->checks();
if(!empty($checks)) {
  die('Your are a spammer');
}
// your code

Available configuration

When you create the object, you have the ability to pass config values through an array.

<?php
$config = [
  'honeypotInputClass'  => 'myCssClass',
  'honeypotInputNames'  => [
    'name1',
    'name2',
  ],
  'formMethod'          => 'GET',
];
$oForm  = new Dominiquevienne\Honeypot\Form($config);

Form

honeypotInputMask

This is the mask used to render the input field. You can use Form::getHoneypotInputMask() to get the current value.

honeypotInputClass

This is the CSS class used on the honeypot input field.

honeypotInputType

This is the HTML type of the input field

honeypotInputName

Way to force a specific name

honeypotInputNames

Array containing a list in which honeypot will take a random name followed by a hash.

formMethod

HTTP Method used to send the form

Honeypot

minFormCompletionTime

Time in seconds under which a form subscriber will be considered as a bot

maxFailureAttempts

Quantity of accepted failures per session before considered as a bot. When the number is reached and failureCheck is ON, every attempt will be considered as a failure during all the session lifetime.

maxAttempts

Quantity of accepted attempts per session before considered as a bot. When the number is reached and quantityCheck is ON, every attempt will be considered as a failure during all the session lifetime.

checks

Array of checks to be made when submitting form. By default, checks are ['timeCheck','honeypotCheck','tokenCheck','failureCheck','quantityCheck']

drupalForm

If set to TRUE, Form::inputs() will return a Drupal FAPI array instead of raw HTML

dominiquevienne/honeypot 适用场景与选型建议

dominiquevienne/honeypot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 231 次下载、GitHub Stars 达 10, 最近一次更新时间为 2017 年 06 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「form」 「spam」 「Honeypot」 「checks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dominiquevienne/honeypot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dominiquevienne/honeypot 我们能提供哪些服务?
定制开发 / 二次开发

基于 dominiquevienne/honeypot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 231
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2017-06-22