2012-09-07 54 views
0

你能帮忙在下面:验证码验证未注册的Joomla工作

我使用用户登录我的的Joomla 1.5网站开始...

的垃圾邮件机器人越来越登记在网站上

虽然我用从现场验证码 - http://www.white-hat-web-design.co.uk/blog/php-captcha-security-images/

其注册页面上的链接工作(不验证) - http://www.mycarhelpline.com/index.php?option=com_user&view=register&Itemid=79

然而,同样是没有得到在注册页面验证,

验证代码

session_start(); 

if(isset($_POST['submit'])) { 

    if($_SESSION['security_code'] == $_POST['security_code'] && 

!empty($_SESSION['security_code'])) { 

     // Insert you code for processing the form here, e.g emailing the 

submission, entering it into a database. 

     echo 'Thank you. Your message said "'.$_POST['message'].'"'; 

     unset($_SESSION['security_code']); 

    } else { 

     // Insert your code for showing an error message here 

     echo 'Sorry, you have provided an invalid security code'; 

    } 

} else { 

} 

在哪个文件/的Joomla线 - Controller.php这样,如default.php和view.html。 PHP我需要把这个代码。我尝试过不同行的不同文件的排列/组合,但不工作。

PL建议

嗨 - 它不工作,甚至进行更改后,事实上它显示服务器错误Controller.php这样 - 把完整的代码在这里

 function register_save() 
    { 
    global $mainframe; 

    // Check for request forgeries 
    JRequest::checkToken() or jexit('Invalid Token'); 

    session_start(); 
    if(isset($_POST['submit'])) { 
      if($_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'])) { 
     // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
      echo 'Thank you.'; 
      unset($_SESSION['security_code']); 
     } else { 
     // Insert your code for showing an error message here 
      echo 'Sorry, you have provided an invalid security code'; 
     } 
    } else { 


    // Get required system objects 
    $user  = clone(JFactory::getUser()); 
    $pathway =& $mainframe->getPathway(); 
    $config  =& JFactory::getConfig(); 
    $authorize =& JFactory::getACL(); 
    $document =& JFactory::getDocument(); 

    // If user registration is not allowed, show 403 not authorized. 
    $usersConfig = &JComponentHelper::getParams('com_users'); 
    if ($usersConfig->get('allowUserRegistration') == '0') { 
     JError::raiseError(403, JText::_('Access Forbidden')); 
     return; 
    } 

    // Initialize new usertype setting 
    $newUsertype = $usersConfig->get('new_usertype'); 
    if (!$newUsertype) { 
     $newUsertype = 'Registered'; 
    } 

    // Bind the post array to the user object 
    if (!$user->bind(JRequest::get('post'), 'usertype')) { 
     JError::raiseError(500, $user->getError()); 
    } 

    // Set some initial user values 
    $user->set('id', 0); 
    $user->set('usertype', $newUsertype); 
    $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO')); 

    $date =& JFactory::getDate(); 
    $user->set('registerDate', $date->toMySQL()); 

    // If user activation is turned on, we need to set the activation information 
    $useractivation = $usersConfig->get('useractivation'); 
    if ($useractivation == '1') 
    { 
     jimport('joomla.user.helper'); 
     $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword())); 
     $user->set('block', '1'); 
    } 

    // If there was an error with registration, set the message and display form 
    if (!$user->save()) 
    { 
     JError::raiseWarning('', JText::_($user->getError())); 
     $this->register(); 
     return false; 
    } 

    // Send registration confirmation mail 
    $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); 
    $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email 
    UserController::_sendMail($user, $password); 

    // Everything went fine, set relevant message depending upon user activation state and display message 
    if ($useractivation == 1) { 
     $message = JText::_('REG_COMPLETE_ACTIVATE'); 
    } else { 
     $message = JText::_('REG_COMPLETE'); 
    } 

    $this->setRedirect('*********', $message); 
} 

回答

0

把您的验证码

文件:components\com_user\controller.php
功能名称:register_save()

此行JRequest::checkToken() or jexit('Invalid Token');

,并设置你的消息变量$message以后。

希望这将工作

+0

嗨 - 它不工作,事实上显示服务器错误,把的完整代码controller.php - pl建议... thnx – Gag