大写和小写都使用getvar

时间:2018-07-09 10:54:25

标签: php

我有现在使用的这段代码:

function onAfterInitialise(){
    $this->username = JRequest::getVar('user', null);
    $this->password = JRequest::getVar('passw', null);

    if(empty($this->username) || empty($this->password))  return true;

    $result = $this->params->get('authmethod','1') === '0' ? $this->plainLogin() : $this->encryptLogin();

    $redirectURL = $this->params->get('urlredirect', null);
    if(!empty($redirectURL)){
        if(!JError::isError($result)){
            $app = JFactory::getApplication();
            $app->redirect($redirectURL);
        }
    }
}

我希望它获得var,即使它是userUSER,也可以是passwPASSW

如何做到?

谢谢

2 个答案:

答案 0 :(得分:2)

第二个参数是默认值,默认值是null。因此,只要只有2个选项-而且也没有User之类的东西-您可以简单地做到:

$this->username = JRequest::getVar('user', JRequest::getVar('USER'));
$this->password = JRequest::getVar('passw', JRequest::getVar('PASSWD'));

答案 1 :(得分:0)

在代码中添加一些其他检查:

$this->username = JRequest::getVar('user', null);
if (empty($this->username)) {
    $this->username = JRequest::getVar('USER', null);
}

$this->password = JRequest::getVar('passw', null);
if (empty($this->password)) {
    $this->password= JRequest::getVar('PASSW', null);
}

// And then proceed as in your code
if(empty($this->username) || empty($this->password))  return true;