0

I am getting this error.I am not able to find out what is causing this error.

//A PHP Error was encountered
//
//Severity: 4096
//
//Message: Object of class stdClass could not be converted to string
//
//Filename: libraries/Template.php
//
//Line Number: 2929

I have made a service page that authinticates the user(login and signup).

I know the code is long and I should have cropped the question,but I am stuck at this since long time now and cant find where the error exist.Can any body help.

Code:

<?php

class autologin_signup {
    /**********SIGNUP FUNCTION************/
    public function signup($member_data_signup){

        $EE_signup = & get_instance(); //Access super Object using this instance within function
        //global $FNS, $IN, $LOC, $TMPL, $DB, $SESS, $PREFS; //deprecated
        $this->group_id     = $member_data_signup['group_id'];
        $this->email      = $member_data_signup['email'];
        $this->screen_name    = str_replace(" ","-",strtolower($member_data_signup['name']));
        $this->password     = $member_data_signup['password'];

        //error_log("Tempcode: ".$this->tempCode."-------Email--------".$this->email."-------Location-------".$this->location."-----Screen Name------ ".$this->screen_name);
        $member_id = $EE_signup->session->userdata['member_id'];

        //error_log("Member_id:".$member_id ."-------".print_r($member_data_signup, 1));

        if(!$member_id){
            $username = $this->email;
            $sql= "SELECT exp_members.password, exp_members.unique_id, exp_members.member_id, exp_members.group_id FROM exp_members WHERE email = '" . mysql_real_escape_string($username) . "'";
            $query = $EE_signup->db->query($sql);


            //  creating a new member starts
            if ($query->num_rows == 0){
                $data['username']         = $this->email;
                $data['password']         = $EE_signup->functions->hash(stripslashes($this->password));
                $data['ip_address']       = $EE_signup->input->ip_address();
                $data['unique_id']        = $EE_signup->functions->random('encrypt');
                $data['join_date']        = $EE_signup->localize->now;
                $data['email']            = $this->email;
                //many more!!!
                $query2 = $EE_signup->db->query("SELECT exp_members.screen_name, exp_members.username, exp_members.group_id FROM exp_members WHERE  screen_name like '%".$screen_name."%'");

                //making a unique screen name code

                if ($query2->num_rows != 0){

                    $countstr = $query2->num_rows;
                    $data['screen_name'] = $screen_name . $countstr;
                }else{
                    $data['screen_name'] = $screen_name;
                }

                $EE_signup->db->query($EE_signup->db->insert_string('exp_members', $data));

                $member_id = $EE_signup->db->insert_id();

                $member_data['member_id']     =   $member_id;
                $member_data['m_field_id_1']  = $this->full_name;
                $member_data['m_field_id_2']  = 0;            //isAccountLinked
                $member_data['m_field_id_8']  = $this->phone_number;
                $member_data['m_field_id_9']  = $member_data_signup['gender'];
                $member_data['m_field_id_13']  = $member_data_signup['newsletter_signed_up'];

                $sql5 = "SELECT exp_members.member_id FROM exp_members WHERE exp_members.email='" . $this->email . "'";
                $query5 = $EE_signup->db->query($sql5);

                $EE_signup->db->query($EE_signup->db->insert_string('exp_member_data', $member_data));
                $member_id = $EE_signup->db->insert_id();

                //Member Creation Complete

            } else { // already  user...
                //echo 'already user';
                echo '-3';

                //exit(0);
            }
            return true;

            /** ----------------------------------------
            /**  Update existing session variables
            /** ----------------------------------------*/
            $EE_signup->session->userdata['screen_name']  = $data['screen_name'];
            $EE_signup->session->userdata['username']     = $data['username'];
            $EE_signup->session->userdata['member_id']    = $data['member_id'];
            $EE_signup->session->userdata['group_id']     = $data['group_id'];

            /** ----------------------------------------
            /**  Update stats
            /** ----------------------------------------*/

            $data = array(
                'member_id'   => $EE_signup->session->userdata['member_id'],
                'name'      => ($EE_signup->session->userdata['screen_name'] == '') ? $EE_signup->session->userdata['username'] : $EE_signup->session->userdata['screen_name'],
                'ip_address'  => $EE_signup->input->ip_address(),
                'date'      => $EE_signup->localize->now,
                'anon'      => 'y',
                'site_id'   => $EE_signup->config->item('site_id')
            );


            $query_12 = "SELECT name FROM exp_online_users WHERE  member_id = '" . $data['member_id'] . "'";
            $query_session = $EE_signup->db->query($query_12);

            if($query_session->num_rows != 0) {
                $EE_signup->db->query($EE_signup->db->update_string('exp_online_users', $data, array("ip_address" => $EE_signup->input->ip_address(), "member_id" => $data['member_id'])));
            } else {
                $EE_signup->db->query($EE_signup->db->insert_string('exp_online_users', $data));
            }
            // login session sets ends

            echo '1'; //signup scuccess
        } else {
            //echo '-3';
            //exit(0);
        }
    }


    /**********LOGIN FUNCTION************/
    public function login($newuserdata) {
        //error_log('in login fucntion here___________________1________________________');
        $EE_login =& get_instance(); //Access super Object using this instance within function
        //echo '<pre>';print_r($newuserdata); echo '</pre>';
        $username = $newuserdata['email'];
        $password = $newuserdata['password'];

        //global $FNS, $IN, $LOC, $TMPL, $DB, $SESS, $PREFS; //deprecated

        $password = $EE_login->functions->hash(stripslashes($password));

        $sql = "SELECT exp_members.password, exp_members.unique_id, exp_members.member_id, exp_members.group_id, exp_members.screen_name
    FROM   exp_members
    WHERE  username = '$username' AND password = '$password'";

        //error_log("in login function ".$sql);

        $query = $EE_login->db->query($sql);
        //error_log('here______________________2_____________________  Member_id: '.$query->row('member_id').'-----NUm Rows: '.$query->num_rows());
        if ($query->num_rows() != 0) {


            ////error_log('here______________________3_____________________');
            /****************************** start session set code ***********************************/
            $EE_login->session->gc_probability = 100;
            $EE_login->session->delete_old_sessions();

            /** ----------------------------------------
            /**  Set cookie expiration
            /** ----------------------------------------*/
            // login session sets start


            // set default expiration to one day
            if ($EE_login->TMPL->fetch_param('expire')) {
                $expire = $EE_login->TMPL->fetch_param('expire');
            }
            /** ----------------------------------------
            /**  Log user in
            /** ----------------------------------------*/
            $expire = 60*60*24*1;

            $EE_login->functions->set_cookie($EE_login->session->c_expire , time()+$expire, $expire);
            $EE_login->functions->set_cookie($EE_login->session->c_uniqueid , $query->row('unique_id'), $expire);
            $EE_login->functions->set_cookie($EE_login->session->c_password , $query->row('password'),  $expire);
            $EE_login->functions->set_cookie($EE_login->session->c_anon , 1,  $expire);

            /** ----------------------------------------
            /**  Create a new session
            /** ----------------------------------------*/
            $EE_login->session->create_new_session($query->row('member_id'));

            /** ----------------------------------------
            /**  Update existing session variables
            /** ----------------------------------------*/

            $EE_login->session->userdata['screen_name']  = $query->row('screen_name');
            $EE_login->session->userdata['username']    = $query->row('username');
            $EE_login->session->userdata['member_id']   = $query->row('member_id');
            $EE_login->session->userdata['group_id']    = $query->row('group_id');


            /** ----------------------------------------
            /**  Update stats
            /** ----------------------------------------*/

            $ip_address = $newuserdata['ip_address'];
            $data = array(
                'member_id'   => $EE_login->session->userdata['member_id'],
                'name'      => ($EE_login->session->userdata['screen_name'] == '') ? $EE_login->session->userdata['username'] : $EE_login->session->userdata['screen_name'],
                'ip_address'  => $ip_address,
                'date'      => $EE_login->localize->now,
                'anon'      => 'y',
                'site_id'   => $EE_login->config->item('site_id')
            );

            //error_log("Member ID: ".$data['member_id']."-------Screen Name--------".$data['name']."-------Location-------".$data['ip_address']);

            $query_12 = "SELECT name FROM exp_online_users WHERE  member_id = '" . $query->row('member_id') . "'";

            $query_session = $EE_login->db->query($query_12);

            if($query_session->num_rows() != 0) {

                $EE_login->db->query($EE_login->db->update_string('exp_online_users', $data, array("ip_address" => $ip_address, "member_id" => $query->row('member_id'))));

            } else {
                $EE_login->db->query($EE_login->db->insert_string('exp_online_users', $data));
            }

            //error_log('here_________________________in login__________________');
            // login session sets ends
            //header("Location: ' . STATIC_URL . 'ee/index.php/register/post-login-normal/");
            //exit(0);
            echo '1';
        } else {
            //not valid username or password
            //do what ever you want to do
            echo 'not_valid';
        }
    }
}

?>
  • 1
    It is not a coincidence that your code is long and also that you have been stuck on it for a long time. If you try and reduce your code down into the smallest possible example which triggers the problem, you will probably find the cause of the problem. Try commenting out parts of your code until you find which bit causes the error, then update your question with only that concise example. – Adrian Macneil Dec 9 '13 at 10:05
  • @AdrianMacneil:alright!!!!i will try tht..thx.But in the error its given that line 2929 causes error..My code is not that big,so which line should i thing it is?just asking – user2133 Dec 9 '13 at 10:06
  • Could you please indicate your EE Version? – Max Lazar Dec 9 '13 at 10:12
  • @MaxLazar:2.4 it is....is it because of that? – user2133 Dec 9 '13 at 10:16
  • similar kind of error ellislab.com/forums/viewthread/186136/#879823 – user2133 Dec 9 '13 at 10:22
2

EE 2.4, in libraries/Template.php on line 2929 we have

if (isset($this->EE->session->userdata[$val]) AND ($val == 'group_description' OR strval($this->EE->session->userdata[$val]) != ''))

line 226 in your code, try to add "0,":

        $EE_login->session->userdata['screen_name']  = $query->row(0,'screen_name');
        $EE_login->session->userdata['username']    = $query->row(0,'username');
        $EE_login->session->userdata['member_id']   = $query->row(0, 'member_id');
        $EE_login->session->userdata['group_id']    = $query->row(0,'group_id');
| improve this answer | |
  • ok....trying...thx for the time though!!! – user2133 Dec 9 '13 at 10:31
  • it is possible, that when you do $query = $EE_login->db->query($sql); (line 187) is return more then 1 result... – Max Lazar Dec 9 '13 at 10:35
  • wohoooooo...its done...Man how did you find it...its working.. – user2133 Dec 9 '13 at 10:37
  • well its working ,but how did you find the error...i mean why was that not working...? – user2133 Dec 9 '13 at 10:43
  • 2
    I just start from the line where this error happens (in template library), indicated possible variables and check where your modify this variables in your code. I think that it is happen because your query on line 187 is return more then one result. In this case ->row is return not string but object which is can't be processed by strval (this function cannot use for objects that do not implement the __toString() method) – Max Lazar Dec 9 '13 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy