2012-09-09 38 views
-1

的Controller.php這樣的代碼,我試圖通過在Controller.php這樣我在做什麼錯的Joomla 1.5

下面使用會話ID驗證的驗證碼是我試圖保存會話驗證碼(通過修改控制的代碼。 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); 
} 
+0

你會得到什麼錯誤? – JvdBerg

回答

1

以下行使用$post代替$_POST

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

後面的代碼,如果條件得到滿足,則會產生一個錯誤(假設它是您正在接收的錯誤)。嘗試更新使用$_POST,它應該修復它:

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

有在代碼塊的幾個地方是引發錯誤 - 這只是許多可能被點火的一個。如果發佈特定錯誤,可能會更容易進行診斷(如果這實際上不能解決問題)。

+0

嗨 - 它顯示錯誤,已經把修改後的代碼...它顯示以下錯誤服務器錯誤 網站在檢索http://www.mycarhelpline.com/index.php?option=com_user&view=login&Itemid=時遇到錯誤79。它可能因維護而關閉或配置不正確。 以下是一些建議: 稍後重新加載此網頁。 HTTP錯誤500(內部服務器錯誤):服務器試圖完成請求時遇到意外情況。 – Gag

+0

沒有會話代碼 - 表單正在保存但雙向驗證碼驗證,我認爲我在會話代碼n中做了一些錯誤captcha驗證 - 尋求幫助... thnx – Gag

+0

@GaganModi修復'$ _POST'錯字允許您的代碼超出最初的會話檢查流程,進入另一個錯誤。在提供的代碼中,拋出'500'錯誤的唯一地方是在'if(!$ user-> bind(JRequest :: get('post'),'usertype')){'block。這段代碼似乎沒有任何特別的錯誤,但是提交請求的表單可能不包含'usertype'字段?嘗試檢查表單和/或提交的數據。 – newfurniturey