Joomla 3.3 会话和安全图像验证码

Posted

技术标签:

【中文标题】Joomla 3.3 会话和安全图像验证码【英文标题】:Joomla 3.3 session and securimage captcha 【发布时间】:2015-02-13 15:11:04 【问题描述】:

我正在为我的模块构建一个表单,最后一步是通过验证码检查以确保安全。我已经下载了最新版本的安全映像。验证码正确显示并且可以生成新的验证码。但是,在表单发布后,检查验证码是否正确输入的建议技术永远不会返回 true。

index.php:

<form method="post" action="tmpl/form/contact.php" name="contactform" id="contactform">
<img id="captcha" src="securimage/securimage_show.php"  />
<a style="text-decoration: none; font-size: 10px; margin-top: -10px; " href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">Refresh</a>
/**input here **/  name="captcha_code" 

contact.php:

define( '_JEXEC', 1 )`;
define( 'JPATH_BASE', realpath(dirname(__FILE__))."/../../../..");
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
$user = JFactory::getUser();
$session = JFactory::getSession();
jimport( 'joomla.application.module.helper' );

$db = JFactory::getDBO();
$db->setQuery("SELECT params FROM #__modules WHERE module = 'module'");
$module = $db->loadObject();
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);


include_once $_SERVER['DOCUMENT_ROOT'] . 'securimage/securimage.php';

$securimage = new Securimage();

if ($securimage->check($_POST['captcha_code']) == false) 

    echo '<div class="error_message">' . $errorcaptchainvalid . '</div>';
  exit;

在搜索了可能是什么问题后,我从http://www.phpcaptcha.org/faq/发现了这种可能性:

如果变量名称相同,这可能是由于 用于跟踪用户及其内容的 PHP 会话 代码是。会话可能未启动或更多 可能在 securimage_show.php 中使用的会话名称不同 来自执行代码的脚本中使用的会话名称 验证。其他软件平台(论坛、内容 管理系统,表单处理器等)使用会话名称其他 比 PHP 的默认值。如果是这种情况,您必须确定什么 会话名称由软件使用,并且使用相同的会话名称 securimage_show.php 和 securimage_play.php。

可以将非默认会话名称传递给 Securimage,以便它可以共享 使用以下代码与另一个软件平台进行会话: $img->session_name = 'your_session_name';

这可以解释为什么我的验证码没有运气。我已经尝试编辑上述文件,但我不知道如何在 Joomla 中设置会话!或者如何解决这个问题。问题可能出在会话变量上吗?

安全图像显示.php:

require_once dirname(__FILE__) . '/securimage.php';


$img = new Securimage();


if (!empty($_GET['namespace'])) $img->setNamespace($_GET['namespace']);


$img->show();

安全图像播放.php

require_once dirname(__FILE__) . '/securimage.php';


$options = array(
    'use_database'    => true,
    'database_name'   => '',
    'database_user'   => '',
    'database_driver' => Securimage::SI_DRIVER_mysql
);


$img = new Securimage();


if (!empty($_GET['namespace'])) $img->setNamespace($_GET['namespace']);


$img->outputAudioFile();

【问题讨论】:

contact.php 第 1 行的额外单引号是否恰好在您在问题中发布的内容中?如果不是,那肯定会导致一些问题。 这里写代码是我的错。文件中的一切都是应有的。 【参考方案1】:

您已经成功了 - 问题在于 Joomla 处理会话的方式。不要将表单放在文章中,而是尝试通过 iframe 嵌入表单,它应该可以正常工作。

【讨论】:

这看起来像是一个答案。也许一些要演示的示例代码会使这成为一个质量更好的答案。

以上是关于Joomla 3.3 会话和安全图像验证码的主要内容,如果未能解决你的问题,请参考以下文章

Joomla 2.5 中的验证码自定义表单

业务安全漏洞总结

基于图像处理和卷积神经网络的文本验证码识别方案

爬虫学习笔记(十七)—— 字符验证码

解读智能识别验证码的验证原理

CURL 如何使用验证码和会话登录