Welcome Guest, Not a member yet? Register   Sign In
Authentication Help
#1

[eluser]codeign00b[/eluser]
Hello everybody Smile
I'm looking for a help in authentication on my site. I have site where users must login to be able to access other part of the site. The problem is when I try to sign in I get the blank page. Sessions are stored in db but it seems like user is not recognized or something. If I write anything in e-mail and password field I get the same blank page.

Here is my code:

Controler (1):

Code:
<?php

class Reports extends CI_Controller {
    
    function index()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
          if (!isset($is_logged_in) || $is_logged_in != true)
        {
            $this->session->set_userdata('redirect_url', 'reports');
            redirect('signin');
            die();
        }
  
        //reports controller part

        //Load reports page
        $data['main_content'] = 'view_reports';
        $this->load->view('view_main', $data);
    }
}

Signin controller:
Code:
<?php

class Signin extends CI_Controller {

    function index()
    {
        //load libraries
        $this->load->library('form_validation');
                $this->load->library('session');
        //Form validation rules
        $this->form_validation->set_rules('useremail', 'E-mail', 'trim|required|valid_email|xss_clean');
        $this->form_validation->set_rules('userpassword', 'Password', 'trim|required|xss_clean');
                                    
        //Run Validation    
        if ($this->form_validation->run() == FALSE)
        {
            //page has not run or validation error
            $data['main_content'] = 'view_signin';
            $this->load->view('view_mainindex', $data);

        }
        else
        {    
            $this->load->model('model_signin');
            $query = $this->model_signin->validate();
            if($query) //If user's credentials validate
            {
            
                 $useremail = $this->input->post('useremail');    
                 $this->session->set_userdata('is_logged_in','true');
                 $this->session->set_userdata('useremail', $this->input->post('useremail'));
                 redirect('reports');    
                        
            }
            else
            {    
                 $data['errors'] = '<p>The email address or password you entered is incorrect.</p>';
             $data['main_content'] = 'view_signin';
             $this->load->view('view_mainindex', $data);
            
                }
            }
    }
    function is_logged_in()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
        
        if (!isset($is_logged_in) || $is_logged_in != true)
        {
            redirect('signin');
            die();
        }
    }
    
    
}

Signin model:
Code:
&lt;?php

class Model_signin extends Model{
    
    function validate()
    {    
        $this->load->helper('date');
        $this->load->helper('url');
        $this->load->library('encrypt');
        $salt = $this->config->item('salt');
        $this->db->where('useremail', $this->input->post('useremail'));
        $password = $this->input->post('userpassword');
        $sha1_password = $this->encrypt->sha1($salt.$password);
        $this->db->where('userpassword', $sha1_password);
        $query = $this->db->get('user');

        if($query->num_rows == 1)
        {    
            //get userid and add it to session data
            $this->db->where('useremail', $this->input->post('useremail'));
            $password = $this->input->post('userpassword');
            $sha1_password = $this->encrypt->sha1($salt.$password);
            $this->db->where('userpassword', $sha1_password);
            $userid = $this->db->get('user')->row()->userid;

            //add timestamp to last loggedin field in user table
            $data = array(
                      'last_login' => now(),
            'last_ip' => $this->input->ip_address()    
                         );
            $this->db->where('userid', $userid);
            $this->db->update('user', $data);
            
            //set userid into session
            $this->session->set_userdata('userid',$userid);
            return true;
            
        }
        else
        {
            return false;
        }
    }

config.php:

Code:
$config['sess_cookie_name']        = 'somesite';
$config['sess_expiration']        = 0;
$config['sess_timeout'] = 7200;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_storage'] = 'database';
$config['sess_database'] = 'default';
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;
$config['sess_http_only'] = TRUE;
$config['sess_secure'] = TRUE;

What is wrong with this?
#2

[eluser]InsiteFX[/eluser]
Look in the CodeIgniter User Guide MY_Controller

InsiteFX
#3

[eluser]codeign00b[/eluser]
Tried that also, no change at all.
#4

[eluser]codeign00b[/eluser]
Any other ideas? It's kinda urgent..

If I use

Code:
class Signin extends Controller {

         function Signin(){
         parent::Controller();
         }

}

Then the view_signin doesnt load properly (blank page).

p.s. The above code (first post) I've already used on one more site and it worked (different server).
#5

[eluser]toopay[/eluser]
First, you need to move this thread from here to another section of this forum. As you can see, this is 'General CodeIgniter Discussion (NO CODE)'.
#6

[eluser]codeign00b[/eluser]
Thank you for the heads up. I'm sorry for posting in the wrong section. If moderators would be so kind to move it to the right section I would be grateful.

And if anyone can help I would be grateful also. For I don't see any error in the code (on this level of knowledge). Can it be a server issue?

Thank you Smile
#7

[eluser]Unknown[/eluser]
It's quite a complex issue
#8

[eluser]codeign00b[/eluser]
It seems that this code doesnt work on the newest CI, but it works without a problem on older versions 2<.

So I think I will downgrade the framework instead of trying to solve the problem (not enough time to do so).

Thank you all for the help and suggestions! I'll be back with more questions for sure Smile


Regards,




Theme © iAndrew 2016 - Forum software by © MyBB