Welcome Guest, Not a member yet? Register   Sign In
redirect problems
#1

[eluser]elmne[/eluser]
My redirect seems to be failing

This is my admin contoller located within the "admin" folder

Code:
<?php

class Admin extends Controller {

    function Admin()
    {
        parent::Controller();    
        $this->load->library('auth');
    }
    
    function index()
    {
      

        $data = array(
          'title' => 'Admin',
        'currentpage' => 'System Administration',
        'content' => 'This is the system Administration'
         );

        $this->load->view('layout/admin/main',$data);        
    }
    
    
    function login()
    {
        $this->auth->restrict(TRUE);

        if ($this->input->post('submit') != FALSE)
        {
            $login = array($this->input->post('username'), $this->input->post('password'));
            if($this->auth->process_login($login))
            {
                // Login successful, let's redirect.
                $this->auth->redirect();
            }
            else
            {
                $data['error'] = 'Login failed, please try again';
                $this->load->vars($data);
            }
        }
        $this->load->view('layout/admin/login');
    }

    function logout()
    {
        if($this->auth->logout())
            redirect('/admin/admin/login');
    }    

}


And this is my auth.php in the libraries

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Auth {

    var $CI = null;
    
     // get the CI Super object
    function __construct(){
        $this->CI =& get_instance();
    }

    function Auth()
    {
        $this->CI->load->library('session');
        $this->CI->load->database();
        $this->CI->load->helper('url');
    }

    function process_login($login = NULL)
    {
        // A few safety checks
        // Our array has to be set
        if(!isset($login))
            return FALSE;
    
        //Our array has to have 2 values
        //No more, no less!
        if(count($login) != 2)
            return FALSE;
    
        $username = $login[0];
        $password = $login[1];
    
        // Query time
        $this->CI->db->where('username', $username);
        $this->CI->db->where('password', $password);
        $query = $this->CI->db->get('user_account_staff');
    
        if ($query->num_rows() == 1)
        {
            // Our user exists, set session.
            $this->CI->session->set_userdata('logged_user', $username);
            return TRUE;
        }
        else
        {
            // No existing user.
            return FALSE;
        }
    }

    function redirect()
    {
        if ($this->CI->session->userdata('redirected_from') == FALSE)
        {
            redirect('/admin/admin');
        } else {
            redirect($this->CI->session->userdata('redirected_from'));
        }
    
    }



    /**
     *
     * This function restricts users from certain pages.
     * use restrict(TRUE) if a user can't access a page when logged in
     *
     * @access    public
     * @param    boolean    wether the page is viewable when logged in
     * @return    void
     */
    function restrict($logged_out = FALSE)
    {
        // If the user is logged in and he's trying to access a page
        // he's not allowed to see when logged in,
        // redirect him to the index!
        if ($logged_out && $this->logged_in())
        {
            redirect('/admin/admin');
        }
    
        // If the user isn' logged in and he's trying to access a page
        // he's not allowed to see when logged out,
        // redirect him to the login page!
        if ( ! $logged_out && ! $this->logged_in())
        {
            $this->CI->session->set_userdata('redirected_from', $this->CI->uri->uri_string()); // We'll use this in our redirect method.
            redirect('/admin/admin/login');
        }
    }
    
    /**
     *
     * Checks if a user is logged in
     *
     * @access    public
     * @return    boolean
     */
    function logged_in()
    {
        if ($this->CI->session->userdata('logged_user') == FALSE)
        {
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }


    function logout()
    {
        $this->CI->session->sess_destroy();
    
        return TRUE;
    }



}
// End of library class
// Location: system/application/libraries/Auth.php


When i try to login at "/admin/admin/login"

I instead get directed to the system's homepage instead of either loading and showing that my logins are incoreect, or if correct, directing me to the admin index controller

and in the url, the path shown is "/admin/login.html"


What's the cause of the problem?
#2

[eluser]daelsepara[/eluser]
perhaps the line:

Code:
if ($this->input->post('submit') != FALSE)

you can simplify to:

Code:
if ($this->input->post('submit'))




Theme © iAndrew 2016 - Forum software by © MyBB