What am i doing wrong in controller.php code of Joomla 1.5
<p>I have tried validating the captcha by using session id in controller.php</p>

<p>Below is the code i have tried for saving captcha session (by modifying controller.php) - but its not working - what am i doing wrong in this code pl suggest</p>

<p>Its showing server error on submission, i've mentioned the original code (before captcha) and revised code (after captcha)</p>

<p><strong>Original Code (Before Captcha Session in Controller.php)</strong></p>

<pre><code> function register_save()
{
    global $mainframe;

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

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

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

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

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

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

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

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

    // If there was an error with registration, set the message and display form
    if ( !$user-&gt;save() )
    {
        JError::raiseWarning('', JText::_( $user-&gt;getError()));
        $this-&gt;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-&gt;setRedirect('https://www.2checkout.com/checkout/spurchase?sid=1689498&amp;product_id=2&amp;quantity=1', $message);
}
</code></pre>

<p><strong>Final Revised Code (as per Modifications suggested now in controller.php)</strong></p>

<pre><code>   function register_save()
  {
    global $mainframe;

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

    session_start();
        $post = JRequest::get( 'post' );
        if(($_SESSION['security_code'] == $post['security_code']) &amp;&amp; (!empty($_SESSION['security_code'])) ) 
        {
        $newUsertype = $usersConfig-&gt;get( 'new_usertype' );
        if (!$newUsertype) 
            {
            $newUsertype = 'Registered'; 
            }
        unset($_SESSION['security_code']);
        } 


        if($_SESSION['security_code'] != $post['security_code'] || $post['security_code']=="")
        {
            JError::raiseWarning('', JText::_( $user-&gt;getError()));
            $this-&gt;register();
            return false;
        }

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

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

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

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

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

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

    // If there was an error with registration, set the message and display form
    if ( !$user-&gt;save() )
    {
        JError::raiseWarning('', JText::_( $user-&gt;getError()));
        $this-&gt;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-&gt;setRedirect('https://www.2checkout.com/checkout/spurchase?sid=1689498&amp;product_id=2&amp;quantity=1', $message);
}
</code></pre>
