Welcome Guest, Not a member yet? Register   Sign In
Blank page controller issue
#1

[eluser]whobutsb[/eluser]
Morning All,
I'm running into a very strange issue where my controllers and methods aren't working predictably.

The auto router goes to the controller: Login and displays the index() method, which is a sign in page which accepts a username and password. The form then redirects to Login/check_login controller. At this point the program shouldn't stay on this page for long. It should either validate and go to the Home controller or redirect back to the login/index page as invalid.

But the browser just hangs on the check_login() method. So I threw in some echos and dies to the method to see if it is reaching a particular point, none were displayed. I even did it in the constructor and received nothing back. I then purposely left out a semicolon which through an error.

I'm not sure whats going on here. Literally it seems like this all worked yesterday and now today its broken.

Any advice on troubleshooting this would be very handy.
Steve


One more note; it seems like CI is adding a cookie to my browser. Before that cookie is added i'm able to display the login form. But after the cookies is added and I try to move back and refresh the page the login display page is blank as well.
#2

[eluser]jedd[/eluser]
[quote author="whobutsb" date="1256753538"]
The form then redirects to Login/check_login controller. At this point the program shouldn't stay on this page for long. It should either validate and go to the Home controller or redirect back to the login/index page as invalid.
[/quote]

I can say with almost total certainty that your problem is in line 27 of this method. Change the j to a z and everything will be fine.

I thank you for not cluttering up the forums with postings of your code - obviously they wouldn't be useful here, as your code is working Just Fine and doesn't need any stinkin' forum users to dirty it with their evil beady eyes ...

You know I could go on.
#3

[eluser]whobutsb[/eluser]
Sorry for not being more specific. But attitude is not needed. Here is the source for my Login controller.

I have a library called Userinfo that is automatically called in the autoload that is used to retrieve and set user information from Active Directory to Memcache. I believe there is an issue with the sessions, but i'm not sure.

Code:
<?php

class Login extends Controller {

    function Login(){
        parent::Controller();
    }
    
    function index(){
        $this->load->view('Login/login_view');
    }


    function check_login(){
        $this->load->library('form_validation');
        
        $this->form_validation->set_error_delimiters("<p class='error'>", "</p>");
        
        $this->form_validation->set_rules('username', 'Username', 'required|trim');
        
        $this->form_validation->set_rules('password', 'Password', 'required|trim');
        
        //Run the Validation
        if(!$this->form_validation->run()){
            
            $this->index();
        
        }else{
        
            $post = $this->input->xss_clean($_POST);
            
            //Check the username and password are correct
            if($this->_check_username_password($post)){
                
                //Log the User In
                $this->_login_user($post['username']);
                
                $this->session->set_flashdata(array('msg_type' => 'success', 'message' => 'You have successfully logged in.'));
                
                redirect('home');
                
            }else{ //Not correct send to login page
                $this->index();
            }
        }
    }
    
    
    function _check_username_password($data){
        
        //Load the Models and Libraries
        $this->load->library('encrypt');
        $this->load->model('HarborForce/User/hfuser_model');
        
        $username = $data['username'];
        
        //Select the password based on the username
        $DBpassword = $this->hfuser_model->select_user_password($username);
        
        //No Password for the user found, send back to login screen
        if(!$DBpassword){
            $this->session->set_flashdata('message', 'The user that was entered does not exist or is no longer a active HarborForce user.');
            return FALSE;
        }
        
        //Decode the DBPassword
        $DBpassword = $this->encrypt->decode($DBpassword->password);
        
        if($DBpassword != $data['password']){
            $this->session->set_flashdata('message', 'The password you entered is incorrect.');
            return FALSE;
        }
        
        return TRUE;
    }
    
    
    function _login_user($username){
    
        //Load the Userinfo Library
        $this->load->library('userinfo');
        
        //Set the Session Data
        $sessiondata = array(
                'harborforce_session'    => array(
                'username'            => strtoupper($username),
                'login_time'        => now(),
                'logged_in'            => TRUE
            )
        );            

        $this->session->set_userdata($sessiondata);
        
        $this->userinfo->set_userinfo($username);    
    }
    
    function logout(){
        $this->session->unset_userdata('harborforce_session');
        $this->session->set_flashdata('message', 'You have successfully logged out');
        redirect('login');
    }
}
#4

[eluser]whobutsb[/eluser]
If I delete the cookie session the login page will appear. If I refresh the page w/o adding any values to the form, a cookie is created and the page is sent back blank.
#5

[eluser]whobutsb[/eluser]
Wow wow wow, alrighty. Found the problem. Yesterday I was working on building some helpers and libraries. And the last thing i did was created a helper called 'string_helper' that creates a Alpha Pagination for some contact indexes.

I totally didn't realize / forgot that string_helper is a default CI helper. And mine was being loaded besides the regular CI one.

I renamed my helper function and the world is back in order.
#6

[eluser]jedd[/eluser]
Ah, yeah .. while the power of over-riding is pretty neat (and new to me, given my non-OO background) I'm always wary about this kind of collision.

To prevent this kind of problem I tend to name all my helper functions with a prefix that denotes the current project - only a few characters - but so that they really stand out when I come back to look at my code later. It's a touch more effort when I strip out useful and generic functions from one app's helper to another, but so far it's been worth the bother.




Theme © iAndrew 2016 - Forum software by © MyBB