Welcome Guest, Not a member yet? Register   Sign In
Admin panel problem
#1

[eluser]Kiran Dangol[/eluser]
Hello everybody,
I am having problem in redirecting the urls in admin panel. I have created a genesis_panel folder inside controller folder. There are two files inside genesis_panel/folder:
1. login.php
2. dashboard.php

Code of login.php is given below:-
Quote:<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

function __construct(){
parent::__construct();
if(!($this->session->userdata('user_log'))){
redirect('genesis_panel/login/index');
}else{
redirect('genesis_panel/dashboard/index');
}
}

public function index()
{
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() === FALSE){
$data['username']=mysql_real_escape_string($this->input->post('username'));
$data['password']=mysql_real_escape_string($this->input->post('password'));
$this->session->set_userdata('user_log',$this->input->post('username'));
redirect('genesis_panel/dashboard/index');
}
$this->load->view('genesis-panel/login');
}

function change_password(){
die('hello');
}

}

Now what the problem is that, I was unable to redirect from the constructor.
Both the urls given same error and says "The page isn't redirecting properly".
But I was able to redirect form the login/index when the form is submitted by removing redirect code of constructor.

One thing,I have declared in routes like
$route['genesis_panel'] = "genesis_panel/login";

Please anyone help me to get out of this problem.
#2

[eluser]InsiteFX[/eluser]
Take the index off the end of your redirects index is default!

Also you may need to setup routes to those.

InsiteFX
#3

[eluser]aquary[/eluser]
Remove the session checking part in the constructor. You cannot access login/index nor login/change_password since the process cannot pass through the constructor without session, which generated by login/index, which got redirected to itself forever.
#4

[eluser]cideveloper[/eluser]
the constructor always runs!

Think about it like this

Somewhere you have a link to "genesis_panel/login". The user clicks the link. If the user is not logged in you redirect to "genesis_panel/login/index". The constructor still runs and thus does the check again. Bingo, it redirects to "genesis_panel/login/index" because the user is not logged in. and it will keep on going forever. A login page doesn't need access control. Anyone should be able to get to the login page. Its after that that you need access control.

Also is it just me or is your form validation saying "if I fail, let the user pass". Or is this just you testing.
#5

[eluser]Kiran Dangol[/eluser]
Thanks Everybody,
Yes, that was the fact which causing an error. I should have checked that session in another controllers.
Many many thanks to every body for taking your time to solve my problem.




Theme © iAndrew 2016 - Forum software by © MyBB