gpt4 book ai didi

php - Magento 客户注册 'Honey Pot' 验证码

转载 作者:搜寻专家 更新时间:2023-10-31 20:48:59 24 4
gpt4 key购买 nike

我以为我已经解决了这个问题,但我遇到了障碍。我想在客户注册表中添加一个“蜜 jar ”,对于那些不熟悉此技术的人来说,该技术涉及使用 CSS 隐藏文本输入并假设普通机器人会想要填写它。然而,人类不会看到该字段,因此它需要验证为空。

我在 Magento 中创建了一个新模块,将以下内容添加到 config.xml 中:

<global>
<fieldsets>
<customer_account>
<honeytrap><create>1</create><update>1</update></honeytrap>
</customer_account>
</fieldsets>
<models>
<customer>
<rewrite>
<customer>MyStore_Honeytrap_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>

然后我在验证函数中添加了一些额外的内容来检查该字段是否为空。据我所知,这一切都是正确的,但在 AccountController.php 中的 line 278 处,extractData() 丢弃了来自在请求中发布数据。我对 Magento 还是很陌生,所以希望也能在这里学到一些东西,但是如何防止该字段被 extractData() 从帖子中删除?

我想我只是想知道我错过了什么,我已经在互联网上阅读了一些关于添加自定义字段的帖子,据我所知这应该有效,但也许我错过了一些东西,因为我不包括实体设置,因为我不需要将此字段保存在数据库中,它纯粹是为了验证注册是否来自人类(尽可能多)。

感谢您的帮助,我敢肯定这可能是我错过的一些荒谬的事情。

编辑:感谢@gordon-knoppe 对使用事件的指点:

public function check_trap(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$post = $event->getControllerAction()->getRequest()->getPost();

// Check Honeytrap is empty
if (Zend_Validate::is( trim($post['fname']) , 'NotEmpty'))
{
$customerHelper = Mage::helper('customer');
$error = $customerHelper->__('A problem has occured with your registration.');
Mage::getModel('customer/session')->addError($error);

Mage::app()->getResponse()
->setRedirect(Mage::getUrl('customer/account', array('_secure' => true)))
->sendResponse();
exit;
}
}

config.xml 中:

    <events>
<controller_action_predispatch_customer_account_createpost>
<observers>
<mystore_honeytrap_observer>
<type>singleton</type>
<class>Mystore_Honeytrap_Model_Observer</class>
<method>check_trap</method>
</mystore_honeytrap_observer>
</observers>
</controller_action_predispatch_customer_account_createpost>
</events>

最佳答案

处理此问题的更独立的方法可能是在相关 Controller 操作 (controller_action_predispatch_*) 之前注册一个观察者,以检测您的表单字段是否已填充,如果已填充,则将它们重定向出去以防止 native 操作处理请求。

关于php - Magento 客户注册 'Honey Pot' 验证码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com