2012-03-13 50 views
0
http://dev."xxxxxyyyyy".com/xxxxx-community/register.html?&invite=5000 

我需要在一個名爲$ fromid使用session.There變量有兩個函數存儲此ID($邀請= 5000)在/components/com_community/controllers/register.php如何使用會話

我應該在哪裏調用這個以及如何?

class CommunityRegisterController extends CommunityBaseController 
{ 
    public function register() 
{ 

} 

另一個

public function register_save() 
{ 
    $mainframe =& JFactory::getApplication(); 
    $modelRegister  = CFactory::getModel('register'); 

    // Check for request forgeries 
    $mySess  =& JFactory::getSession(); 

    if(! $mySess->has('JS_REG_TOKEN')) 
    { 
     echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_SESSION') . '</div>'; 
     return;  
    } 

    $token  = $mySess->get('JS_REG_TOKEN',''); 
    $ipAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 
    $authKey = $modelRegister->getAssignedAuthKey($token, $ipAddress); 
    $formToken = JRequest::getVar('authkey', '', 'REQUEST'); 

    if(empty($formToken) || empty($authKey) || ($formToken != $authKey)) 
    { 
     //echo $formToken .'|'. $authKey; 
     echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_TOKEN') . '</div>'; 
     return; 
    } 

    //update the auth key life span to another 180 sec. 
    $modelRegister->updateAuthKey ($token, $authKey, $ipAddress); 

    // Get required system objects 
    $config  = CFactory::getConfig(); 
    $post  = JRequest::get('post'); 

    // If user registration is not allowed, show 403 not authorized. 
    $usersConfig = &JComponentHelper::getParams('com_users'); 
    if ($usersConfig->get('allowUserRegistration') == '0')  
    { 
     //show warning message  
     $view =& $this->getView('register'); 
     $view->addWarning(JText::_('COM_COMMUNITY_REGISTRATION_DISABLED')); 
     echo $view->get('register');          
     return; 
    } 

我可以訪問使用該類$ fromid在組件/ com_users /控制器/ registration.php的

class UsersControllerRegistration extends UsersController 

{ 

} 
+0

http://www.phphelps.com/11_How_to_use_session.shtml – 2012-03-13 06:01:17

回答

0

您可以使用GET方法獲取的值,然後將其存儲在會話變量, 例如:

$_SESSION['fromid'] = $_GET['invite']; 
$fromid = $_SESSION['fromid']; 
+0

register.php是其中的用戶的所有信息存儲在表中的位置。所以我可以在components/com_users/controllers/registration.php中使用它,因爲它是用戶註冊的地方。管理員可以調用是否激活該特定配置文件。或者我應該將其存儲在數據庫中。 – 2012-03-13 06:17:15