Welcome Guest, Not a member yet? Register   Sign In
Form Validation Always False (Registered Domain Name Issue)
#1

Hi guys,

I have an issue with my Codeigniter website whenever I change the base_url to my registered domain name.

When I use the elastic IP address of my AWS EC2 instance (Windows 2012 R2 AMI), everything works fine - even when I access the website externally via elastic IP, the form validation works.

However, when I switch the base_url to my registered domain name, whenever I try to log-in, the form validation always returns false. I'm pasting the code here for your reference.

FYI, I've enabled CSRF protection and Session cookies.

controller-login.php
Code:
 public function login(){
    $this->form_validation->set_rules('username','Username','trim|required|min_length[4]');
    $this->form_validation->set_rules('password','Password','trim|required|min_length[4]');
    
        if($this->form_validation->run() == FALSE){
            $this->load->view('admin/layouts/login');
echo validation_errors();
//THIS IS WHAT ALWAYS POPS UP EVERY TIME I TRY TO LOG-IN WHEN BASE_URL IS SET TO MY DOMAIN NAME
//But there are no validation errors being displayed.
        } else {
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            
            $user_id = $this->Authenticate_model->login_user($username,$password);
            
            if ($user_id){
                $user_data = array('user_id'=>$user_id,'username'=>$username,'logged_in'=>true);
                $this->session->set_userdata($user_data);
                
                $this->session->set_flashdata('pass_login','You are now logged in.');
                redirect('admin/dashboard');
            } else {
echo 'Error';
}
        }
    }

Authenticate_model.php
Code:
public function login_user($username,$password) {
        //$enc_password = md5($password);
        
        $this->db->where('admin_username',$username);
        $this->db->where('admin_password',$password);
        
        $result = $this->db->get('Admin');
        
        if($result->num_rows() == 1){
            return $result->row();
        } else {
            $this->session->set_flashdata('fail_login','No such user.');
            redirect('admin/login');
        }
    }
BTW, I've had my domain name point to the elastic IP address of my EC2 instance containing my Codeigniter website. I'm not sure if this is significant but the IP address uses a port. That's all.
Thank you guys so much for your help in advance.
Reply
#2

You not say how you make sure if user is logged in, so just saying what normally my issue with this.

Could be that your session is not getting set on when specifying domain name, just make sure your cookie settings in config file is on defaults and if you use files as driver that apache/web_user have access to write the files. That normally my issue with login problems.

L:
Reply
#3

(07-06-2017, 11:26 PM)karman Wrote: You not say how you make sure if user is logged in, so just saying what normally my issue with this.

Could be that your session is not getting set on when specifying domain name, just make sure your cookie settings in config file is on defaults and if you use files as driver that apache/web_user have access to write the files.  That normally my issue with login problems.

L:

Do you mean setting the cookie_domain values? How do you configure your apache files?
Reply
#4

Hi, sorry, notifications not setup so only see your question now.

Just make sure your cookie values are the defaults. If you use file based session, make sure apache user has RW on the folder where they get saved.

For debugging:
I normally set the "logged in " session variable and then reading it immediatly after. If its not getting set then you know its config issue somewhere. if getting set, then maybe code logic.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB