Welcome Guest, Not a member yet? Register   Sign In
How to fix default controller redirect
#1

[eluser]titolancreo[/eluser]
Hi!

I'm new programming with codeigniter and I was solving all problems I had by myself, but now, I need some help.

Yesterday I was surfing my web whitout problems until I had one with ajax. I couldn't go to controller so I think that was the problem, but this morning, my session has expired and I notice that when I try to log in, it always load my default controller.

I think the problem starts because I was changing a lot of things in order to configure xdebug for netbeans.

Here is my code:

config:
Code:
$config['uri_protocol'] = 'REQUEST_URI';

htaccess:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

routes:
Code:
$route['default_controller'] = "login";
$route['404_override'] = '';

(controller) login:
Code:
function index()
  {
        if($this->session->userdata('logged_in'))
        {
            $session_data = $this->session->userdata('logged_in');
            $data['nick'] = $session_data['nick'];
            $data['header'] = "inicio";
            $this->load->view('inicio_view', $data);
        }
        else
        {
            $this->load->helper('form');
            $this->load->view('login_view');
        }
        
  }

(view) login_view:
Code:
<?php $attributes = array('onsubmit' => 'return checkLog();', 'id' => 'formLogin');
                            echo form_open('verifylogin', $attributes); ?>
                        <label for="email" >Usuario:</label>
                        &lt;input size="27" type="text" name="email" id="user" placeholder="email"/&gt;&lt;br/><br/>
                        <label for="password" >ContraseƱa:</label>
                        &lt;input size="27" type="password" name="password" id="pass"  placeholder="******"/&gt;&lt;br/>
                        <div id="error" class="error">
                           &lt;?php if (isset($login_errors)) echo $login_errors; ?&gt;
                        </div>
                        &lt;input type="submit" name="submitLogin" value="Login" class="bt_login" /&gt;
                     &lt;/form&gt;

And I want to go to verifylogin but I don't know why, if I debug it, It goes always to login

Thanks a lot for your answers!!!
#2

[eluser]Otemu[/eluser]
Can we see your verifylogin controller??
#3

[eluser]titolancreo[/eluser]
[quote author="Otemu" date="1364209245"]Can we see your verifylogin controller??[/quote]

Yes, but it never goes there. I have breakpoints in login and verifylogin and it only stops in login, so that's not the problem... Yesterday, when I tried to logout, I could login again, and I didn't change anything in that controller.

Code:
function index()
  {
    $this->load->library('form_validation');
    
    
    if($this->input->post('submitLogin'))
    {
                $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean');
                $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
                $this->form_validation->set_error_delimiters('', '');
    }
    
      
    if($this->form_validation->run() == FALSE)
    {
      //Field validation failed.  User redirected to login page
        if($this->input->post('submitLogin'))
        {
            $data['login_errors'] = validation_errors();
        }
      
      $this->load->view('login_view', $data);
    }
    else
    {
      //Go to private area
      redirect('home', 'refresh');
    }
    
  }

I have $this->input->post('submitLogin') because I have two forms on login_view
#4

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

In your.htaccess file, change this:
Code:
RewriteRule ^(.*)$ index.php/$1 [L]

to this:
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]

You may also need to change the following:
Code:
$config['uri_protocol'] = 'REQUEST_URI'; // Try the other possible values.

I suspect your server is misinterpreting the request URI.
#5

[eluser]titolancreo[/eluser]
[quote author="TheFuzzy0ne" date="1364210768"]Welcome to the CodeIgniter forums!
[/quote]

Thanks!! I hope I'll learn a lot here ;-)


It doesn't work, I'm desperate...

I also have
Code:
$config['enable_query_strings'] = TRUE;


Watching source code, i found that I have this action
Code:
http :// localhost/PFC/?verifylogin
If I change it to:
Code:
http :// localhost/PFC/verifylogin

it works, but it is created by the form_open('verifylogin', $attributes).

Any ideas?
#6

[eluser]TheFuzzy0ne[/eluser]
Are you sure you want to enable query strings?

By default, they're disabled, so your URL would be something like:

http://localhost/controller/method/arg1/arg2

With query strings enabled, your URL would be more like:

http://localhost/?c=controller&m=method&...g&arg2=arg

Is that what you want?
#7

[eluser]titolancreo[/eluser]
I know it, its only for debugging purpose because netbeans (xdebug) needs to send its session
#8

[eluser]TheFuzzy0ne[/eluser]
I think that's why you have a problem. Is it really worth sacrificing clean URLs so you can use a debugger?

The CodeIgniter profiler works just fine for me. Granted, it's not a debugger, but it helps with benchmarking.
#9

[eluser]titolancreo[/eluser]
Thanks a lot!

That was the problem... I change it to false and it works perfect.




Theme © iAndrew 2016 - Forum software by © MyBB