Welcome Guest, Not a member yet? Register   Sign In
Commands out of sync; you can't run this command now
#5

(This post was last modified: 12-31-2015, 06:12 AM by mike7418.)

(12-30-2015, 08:47 AM)mwhitney Wrote: Maybe we could help if you could elaborate on the problem a little. You seem to be under the impression that you're running into a session concurrency issue, but the error message you've posted comes from MySQL under many different circumstances. For one, make sure you do not have pconnect enabled in your default database configuration.

pconnect is disabled, I have a login that after the member is verified it sets session variables then redirects you back to the page you logged in from. I have checked session state right up to the redirect, then it is dropped. I have session autoloaded, here is the authentication functions

PHP Code:
function authenticate($username$password$page) {
        
//$this->load->model ( 'Db_model' );
        
        // query the db and send back result
        
$authenticate $this->authenticate_user $username$password );
        
// print_r($authenticate);
        
if (is_array $authenticate )) {
            
//echo 'returned from authenticating';
            // set session values
            
$this->set_session_values($authenticate);
            
//var_dump($this->session->all_userdata());
            //session_commit();
            
if (isset($_SESSION['user_id'])) {
 
                               // testing to ensure session state
                
$msg "Sessions were set correctly";
                
$this->do_alert($msg);
 
                               // the redirect is what will be normal after fixing the session problem
                //redirect ( base_url ( $page ), 'location', 301 );
            
} else {
                
$msg "Error: Sessions were not set correctly.";
                
$this->do_alert($msg);
            }
            
        } elseif (
preg_match '/\bError\b/i'$authenticate )) {
            
$this->do_alert $authenticate );;
        }
    }
    function 
authenticate_user($username$password) {
        
//echo 'inside of authenticate_user';
        // CALL `mike7418_greyhorse`.`sp_authenticate`(<{in_username VARCHAR(16)}>, <{in_password VARCHAR(255)}>);
        
$auth $this->db->query "CALL sp_authenticate('{$username}');" );
        
$crypt $this->config->item 'encryption_key' );
        if (
$auth->num_rows () > 0) {
            foreach ( 
$auth->result () as $key ) {
                
//$pwd = $this->encrypt->decode ( $key->password, $crypt );
                // print $pwd;
                //$pattern = '/\b' . $password . '\b/i';
                
if (password_verify($password$key->password)) {
                    
//echo "Password matched";
                    
if ($key->active == 0) {
                        return 
'Error: Member account is not currently active.';
                    } elseif (
$key->blocked == 1) {
                        return 
'Error: Member account has been blocked. Please contact customer service for further information';
                    }
                    
$session = array (
                            
'user_id' => $key->user_id,
                            
'firstname' => $key->firstname,
                            
'state' => $key->state,
                            
'zipcode' => $key->zipcode,
                            
'active' => $key->active,
                            
'user_role' => $key->user_role
                    
);
                    return 
$session;
                } else {
                    return 
"Error: Password entered does not match";
                }
            }
        } else {
            return 
'Error: Authentication failed, please try again';
        }
    } 

Everything says to run session_write_close() or session_commit() * An alias of session_write_close() because I keep getting the 'Commands out of sync'. So the first line of the function is the session_write_close(). I've tried to set a variable with the session before the close and that doesn't work either. session variable is already unset in the redirect.

PHP Code:
function index() {
$sess_fname $this->session->userdata('firstname');
//etc...

session_commit();

// the rest of the code....

Not sure if it would make a difference? But maybe I should add that I am also using Zurb Foundation CSS framework in the layout also???
Reply


Messages In This Thread
RE: Commands out of sync; you can't run this command now - by mike7418 - 12-31-2015, 05:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB