• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to fix this error?

#1
[eluser]chmod[/eluser]
controller:

Code:
function ilogin(){
         $username = $this->input->post('input_username');
         $password = $this->input->post('input_password');
         $sig_key = $this->input->post('sig_key');

        //将表名存入session中
        $tablename = $this->security_model->getMemberTableName($username);
        $session_data = array('tablename' => $tablename);
        $this->session->set_userdata($session_data);

         $this->form_validation->set_rules('input_username','lang:label_username','trim|xss_clean|required|callback_checkUserPass');
        $this->form_validation->set_rules('input_password','lang:label_password','trim|xss_clean|required');
        $this->form_validation->set_rules('sig_key', 'lang:sig_key', 'callback_checkSigKey');

        if ($this->form_validation->run() === FALSE){
             $data = array('title' => $this->lang->line('page_title_login'));
             $this->load->view('center/login_main_tpl', $data);
        }else{
            $pid = $this->security_model->getUserPid($username)->pid;
            $md5password = $this->security_model->getUserPid($username)->md5Password;
            $nickname = $this->security_model->getIdByPid($username)->nickname;
            $exps = $this->security_model->getUserExps($username)->exps;
            $goldCoins = $this->security_model->getUserGoldCoins($username)->goldCoins;
            $credits = $this->security_model->getUserCredits($username)->credits;
            $ranks = $this->security_model->getUserRanks( $exps );
            $payType = $this->security_model->getUserPayType($username)->payTypeName;
            $groupId = $this->security_model->getIdByPid($username)->groupId;

            $session_data = array(    'session_id_saved' => $this->session->userdata('session_id'),
                                    'username' => $username,
                                    'pid' => $pid,
                                    'md5password' => $md5password,
                                    'nickname' => $nickname,
                                    'exps' => $exps,
                                    'goldCoins' => $goldCoins,
                                    'credits' => $credits,
                                    'ranks' => $ranks,
                                    'payType' => $payType,
                                    'groupId' => $groupId);
            $this->session->set_userdata($session_data);

            $forward = $this->session->userdata('forward');
            if (!empty($forward)){
                redirect($forward, 'refresh');
            }else{
                $username = $this->session->userdata('username');
                $data = array(    'username' => $this->session->userdata('username'),
                                'nickname' => $nickname,
                                'credits' => $credits,
                                'ranks' => $ranks,
                                'goldCoins' => $goldCoins,
                                'serviceStartTime' => $this->security_model->getIdByPid($username)->serviceStartTime,
                                'serviceEndTime' => $this->security_model->getIdByPid($username)->serviceEndTime,
                                'totalFillTimes' => $this->security_model->getIdByPid($username)->totalFillTimes,
                                'payType' => $payType);
                $this->load->view('center/mycenter_tpl',$data);
            }
        }
     }

when I submit username and password,but empty sigKey,
the CI noted me following error message:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: 4096</p>
<p>Message: Object of class CI_DB_mysql_result could not be converted to string</p>
<p>Filename: libraries/Form_validation.php</p>
<p>Line Number: 1205</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Object of class CI_DB_mysql_result to string conversion</p>
<p>Filename: libraries/Form_validation.php</p>
<p>Line Number: 1205</p>

how can i fix these error?

#2
[eluser]TheFuzzy0ne[/eluser]
You're model should probably be returning either an array or an object. You can't use the result object directly:
Code:
$res = $this->db->get('some_table');

$res = $res->result_array();

# OR

$res = $res->result();

#3
[eluser]chmod[/eluser]
but I input username like:free_spy, and password:MYPASS
the table name will be something.Because:
Code:
function Tablination($username){
        $md5Username = md5($username);
        $lastTableName = mb_substr($md5Username,0,1);
        return $lastTableName;
    }

     function getMemberTableName($username){
        $tablename = $this->lang->line('table_name_member_pre');
        $tablename .= $this->tablination_model->Tablination($username);
        if (!empty($tablename)){
            return $tablename;
        }else{
            return false;
        }
     }

the table name will return a value.

do you thing so?

#4
[eluser]chmod[/eluser]
[quote author="TheFuzzy0ne" date="1246894103"]You're model should probably be returning either an array or an object. You can't use the result object directly:
Code:
$res = $this->db->get('some_table');

$res = $res->result_array();

# OR

$res = $res->result();
[/quote]

I debug like following:

Code:
$username = $this->input->post('input_username');
         $password = $this->input->post('input_password');
         $sig_key = $this->input->post('sig_key');
        $tablename = $this->security_model->getMemberTableName($username);
        $session_data = array('tablename' => $tablename);
        $this->session->set_userdata($session_data);

         $this->form_validation->set_rules('input_username','lang:label_username','trim|xss_clean|required|callback_checkUserPass');
        $this->form_validation->set_rules('input_password','lang:label_password','trim|xss_clean|required');
        var_dump($this->form_validation->run()); //----&gt;output boolean(true)
        exit;
        $this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean|required|callback_checkSigKey');
        echo $this->session->userdata('sig_key');
        var_dump($this->form_validation->run()); //-----&gt;output error information
exit;

/*
A PHP Error was encountered

Severity: 4096

Message: Object of class CI_DB_mysql_result could not be converted to string

Filename: libraries/Form_validation.php

Line Number: 1205
A PHP Error was encountered

Severity: Notice

Message: Object of class CI_DB_mysql_result to string conversion

Filename: libraries/Form_validation.php

Line Number: 1205


*/

my callback checkSigKey function like these:
Code:
function checkSigKey(){
         if ($this->session->userdata('sig_key') !== $this->input->post('sig_key')){
             $this->form_validation->set_message('checkSigKey', $this->lang->line('sig_key_invalid'));
             return false;
         }else{
             return true;
         }
     }

what's the problem?

#5
[eluser]chmod[/eluser]
I am sure the problem in these codes:
Code:
$this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean|required|callback_checkSigKey');

my callback function:
Code:
function checkSigKey(){
         if ($this->session->userdata('sig_key') !== $this->input->post('sig_key')){
             $this->form_validation->set_message('checkSigKey', $this->lang->line('sig_key_invalid'));
             return false;
         }else{
             return true;
         }
     }
I can not find any errors.

some one help me?

#6
[eluser]patrickpopowicz[/eluser]
Have you tried passing the sig_key through the callback instead of using it from the input post (see below)? Is your callback in your controller and do you get the same error when you remove the callback function from the validation?

Code:
$this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean|required|callback_checkSigKey');

function checkSigKey($sig_key)
{
    if ($sig_key !== $this->session->userdata('sig_key'))
    {
        $this->form_validation->set_message('checkSigKey', $this->lang->line('sig_key_invalid'));
        return false;
    }
    else
    {
        return true;
    }
}

#7
[eluser]chmod[/eluser]
[quote author="ppopowicz" date="1246906227"]Have you tried passing the sig_key through the callback instead of using it from the input post (see below)? Is your callback in your controller and do you get the same error when you remove the callback function from the validation?

Code:
$this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean|required|callback_checkSigKey');

function checkSigKey($sig_key)
{
    if ($sig_key !== $this->session->userdata('sig_key'))
    {
        $this->form_validation->set_message('checkSigKey', $this->lang->line('sig_key_invalid'));
        return false;
    }
    else
    {
        return true;
    }
}
[/quote]

I try the above code.but the error is occur.
When I remove one by one of the rules:
Code:
$this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean|required');

Code:
$this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean');

the code become success.
the required rules and callback function error.

but if i remove the sig_key. username and password use required rules and callback function, these are ok.

why ?

#8
[eluser]patrickpopowicz[/eluser]
When I build a quick form and validation for the sig_key, I'm not running into any problems. Everything submits, and validates okay including trim, xss_clean, required and the callback function.

There is something else causing the error. After looking at the code again, you are using non-validated variables to make your calls to the databases. You are setting them ($username, $password, and $sig_key) before you even validate the data, you should be setting those AFTER you validate okay.

In your original code, where are you setting the sig_key to the session? If you aren't setting it at all the callback will fail.

#9
[eluser]chmod[/eluser]
[quote author="ppopowicz" date="1246909769"]When I build a quick form and validation for the sig_key, I'm not running into any problems. Everything submits, and validates okay including trim, xss_clean, required and the callback function.

There is something else causing the error. After looking at the code again, you are using non-validated variables to make your calls to the databases. You are setting them ($username, $password, and $sig_key) before you even validate the data, you should be setting those AFTER you validate okay.

In your original code, where are you setting the sig_key to the session? If you aren't setting it at all the callback will fail.[/quote]


after set sig_key to the session using "http://192.168.134.135/sig/", then I validate it .


in view:
Code:
&lt;?=form_open('center/login/ilogin');?&gt;
    <div class="dlu">
        <div class="dlu1">
            <div class="dlu1_1">&lt;?=$this->lang->line('label_username');?&gt;</div>
            <div class="dlu1_2">
                &lt;input id="input_username" name="input_username" type="text" value="" class="bc_ipt1" /&gt;
            </div>
        </div>
        <div class="dlu1">
            <div class="dlu1_1">&lt;?=$this->lang->line('label_password');?&gt;</div>
            <div class="dlu1_2">
                &lt;input id="input_password" name="input_password" type="password" value=""  class="bc_ipt1" /&gt;
            </div>
        </div>
        <div>
            <span class="">验证码&nbsp;:</span>
            <span>&lt;input id="sig_key" name="sig_key" type="text" value="" /&gt;&lt;/span>
            <span>
                <a id="sig_refresh_img" name="sig_refresh_img" href="#">
                    <img alt="SIG" id="sig_img" name="sig_img" src="http://192.168.134.135/sig/" />
                </a>
            </span>
            <span>
                <a id="sig_refresh_text" name="sig_refresh_text" class="" href="#">refresh</a>
            </span>
        </div>
        <div class="dlu2" id="submit">
            &lt;input type="image" src="&lt;?=IMG_URL;?&gt;center/bc3.jpg" /&gt;
        </div>
    </div>
&lt;?=form_close();?&gt;


the controller:
Code:
function ilogin(){
         $username = $this->input->post('input_username');
         $password = $this->input->post('input_password');
         $sig_key = $this->input->post('sig_key');

        //将表名存入session中
        $tablename = $this->security_model->getMemberTableName($username);
        $session_data = array('tablename' => $tablename);
        $this->session->set_userdata($session_data);

         $this->form_validation->set_rules('input_username','lang:label_username','trim|xss_clean|required|callback_checkUserPass');
        $this->form_validation->set_rules('input_password','lang:label_password','trim|xss_clean|required');
        $this->form_validation->set_rules('sig_key', 'lang:sig_key', 'trim|xss_clean|callback_checkSigKey');

        if ($this->form_validation->run() === false){
             $data = array('title' => $this->lang->line('page_title_login'));
             $this->load->view('center/login_main_tpl', $data);
        }else{
            $pid = $this->security_model->getUserPid($username)->pid;
            $md5password = $this->security_model->getUserPid($username)->md5Password;
            $nickname = $this->security_model->getIdByPid($username)->nickname;
            $exps = $this->security_model->getUserExps($username)->exps;
            $goldCoins = $this->security_model->getUserGoldCoins($username)->goldCoins;
            $credits = $this->security_model->getUserCredits($username)->credits;
            $ranks = $this->security_model->getUserRanks( $exps );
            $payType = $this->security_model->getUserPayType($username)->payTypeName;
            $groupId = $this->security_model->getIdByPid($username)->groupId;

            $session_data = array(    'session_id_saved' => $this->session->userdata('session_id'),
                                    'username' => $username,
                                    'pid' => $pid,
                                    'md5password' => $md5password,
                                    'nickname' => $nickname,
                                    'exps' => $exps,
                                    'goldCoins' => $goldCoins,
                                    'credits' => $credits,
                                    'ranks' => $ranks,
                                    'payType' => $payType,
                                    'groupId' => $groupId);
            $this->session->set_userdata($session_data);

            $forward = $this->session->userdata('forward');
            if (!empty($forward)){
                redirect($forward, 'refresh');
            }else{
                $username = $this->session->userdata('username');
                $data = array(    'username' => $this->session->userdata('username'),
                                'nickname' => $nickname,
                                'credits' => $credits,
                                'ranks' => $ranks,
                                'goldCoins' => $goldCoins,
                                'serviceStartTime' => $this->security_model->getIdByPid($username)->serviceStartTime,
                                'serviceEndTime' => $this->security_model->getIdByPid($username)->serviceEndTime,
                                'totalFillTimes' => $this->security_model->getIdByPid($username)->totalFillTimes,
                                'payType' => $payType);
                $this->load->view('center/mycenter_tpl',$data);
            }
        }
     }

#10
[eluser]patrickpopowicz[/eluser]
First, nowhere in the above code do you set the sig_key in the session, so when the callback is being tested, it will return FALSE every time causing the validation to fail. Even then you are not requiring it in your validation rule.

Second, you didn't rework the code at all. You are still using the POST data to set variables before you are validating the data, which you are then using to make calls to the database.

Clean up your code, there are many more issues with the code than just the validation.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.