-1

controller.php でセッション ID を使用してキャプチャの検証を試みました

以下は、キャプチャセッションを保存するために試したコードです(controller.phpを変更して)-しかし、機能していません-このコードで何が間違っているのでしょうかplは提案します

送信時にサーバーエラーが表示されます。元のコード (キャプチャ前) と修正されたコード (キャプチャ後) について言及しました。

元のコード (Controller.php の Captcha セッションの前)

 function register_save()
{
    global $mainframe;

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

    // 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('https://www.2checkout.com/checkout/spurchase?sid=1689498&product_id=2&quantity=1', $message);
}

最終改訂コード (controller.php で現在提案されている変更による)

   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']) && (!empty($_SESSION['security_code'])) ) 
        {
        $newUsertype = $usersConfig->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->getError()));
            $this->register();
            return false;
        }

    // 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';
    }

    // 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('https://www.2checkout.com/checkout/spurchase?sid=1689498&product_id=2&quantity=1', $message);
}
4

1 に答える 1

1

次の行では、$post代わりに を使用してい$_POSTます。

if($_SESSION['security_code'] != $post['security_code'] || $post['security_code']=="")

条件が満たされた場合、次のコードはエラーを発生させます (それがあなたが受け取っているものであると仮定します)。使用するために更新してみて$_POSTください。修正されるはずです。

if($_SESSION['security_code'] != $_POST['security_code'] || $_POST['security_code']=="")

コード ブロックにはエラーが発生する場所がいくつかあります。これは、発生する可能性のある多くの場所の 1 つにすぎません。特定のエラーを投稿すると、診断が容易になる場合があります (これで実際に問題が解決しない場合)。

于 2012-09-09T20:27:02.283 に答える