Welcome Guest, Not a member yet? Register   Sign In
strange url changing ...
#1

[eluser]raimon[/eluser]
Hi forum,

I'm learning CodeIgniter, and trying to figure out how it works, so I'm playing a little ...

Now, if I write this url:

http://127.0.0.1/igni/

I get a 404 Page not found, and the url now is: http://127.0.0.1/igni/index.php/login


Code:
The config.php option is:
$config['index_page'] = "index.php";

Code:
Inside Controllers, I have a file called index.php:
<?php

class Index extends Controller {

    function __construct()
{    parent::Controller();
    
    $this->load->library('Erkanaauth');

}
    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        echo "hola";
    //    $this->load->view('login');
    }
}
?>


So, any idea why CodeIgniter is changing the URL o why is not going to index.php, inside applications/controllers ?

any idea where to lookfor, something that maybe has been changed by me inadvertely ?

thanks in advance!!

regards,

raimon fernandez
#2

[eluser]gtech[/eluser]
Im only guessing but what is your default_controller set to in the config/routes.php?

if it is 'login' then that might explain why its jumping to a login controller.


[edit] I am not sure if naming a controller Index is a good thing, as each controller may have a function called index.
#3

[eluser]Armchair Samurai[/eluser]
Did you change your default controller to "Index" in routes.php?

[edit]gtech beat me to it...[/edit]
#4

[eluser]raimon[/eluser]
[quote author="gtech" date="1195544722"]Im only guessing but what is your default_controller set to in the config/routes.php?

if it is 'login' then that might explain why its jumping to a login controller.

ok, thanks, that's it, I know it was a really stupid mistake for my part, I had another name there ...

[edit] I am not sure if naming a controller Index is a good thing, as each controller may have a function called index.[/quote]

ok, I'll change it, you're right.

thanks both of you, now it works ...


regards,


raimon fernandez
#5

[eluser]raimon[/eluser]
well, it was working until now ...

I've changed the routes.php:
Code:
$route['default_controller'] = "welcome"; // "welcome";

the main site is:
Code:
http://127.0.0.1/igni/

the welcome.php is:
Code:
<?php

class Welcome extends Controller {

    function __construct()
{    parent::Controller();
    
    $this->load->library('Erkanaauth');

}
    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
    $this->load->view('login');
    }
}
?>


the view 'login.php' is:
Code:
<?= form_open('user/validatelogin/'); ?>

    <p><label for="username">Username:</label><br />
    &lt;input type="text" name="username" id="username" /&gt;</p>

    <p><label for="password">Password:</label><br />
    &lt;input type="password" name="password" id="password" /&gt;</p>

    <p>&lt;input type="submit" value="Login" /&gt;</p>

&lt;?= form_close(); ?&gt;


and user.php is:
Code:
&lt;?php

class User extends Controller
{

    function __construct()
{    
    parent::Controller();
    
//     $this->load->library('Erkanaauth');
    
}

    function validatelogin()
    {
        $this->load->library('validation');
        $rules['user'] = "required";
        $rules['password'] = "required";
        $this->validation->set_rules($rules);
        
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        
        if($this->validation->run()==False)
        {
            $this->load->view('login');
        }
        else
        {
            $this->checklogin($username, $password);
        }
    }


    function checklogin($username, $password)
    {
        $this->load->helper('security');
            
        if ($this->erkanaauth->try_login(array('username'=>$user_name, 'password'=>$password)))
        {
            //return True;
            echo "connection OK";
        }
        else
        {
            $this->validation->set_message('_check_login','Incorrect login info.');
            //return False;
            echo "error in login";
        }
    }
}
?&gt;


the problem:
-------------------

after writing 127.0.0.1 as expected, I received the login page.

the form tag is:
Code:
&lt;form action="index.php/user/validatelogin" method="post"&gt;


if I submit with missing values, I receive the same login page, but the form tag has changed into:
Code:
&lt;form action="index.php/user/validatelogin" method="post"&gt;

and of course, if I submit again the form, I get a 404 error not found, and the browser's address is:
Code:
http://127.0.0.1/igni/index.php/user/index.php/user/validatelogin

I know the form_open helper puts the url, but I don't understand what I'm doing wrong here ...

thanks again for your help,

regards

r.
#6

[eluser]gtech[/eluser]
you can use base_url() so the full url path can be defined as otherwise it will redirect relative to your controller.

Code:
&lt;form action="&lt;?=base_url()?&gt;index.php/user/validatelogin"&gt;

To use base_url you need to load the url helper in your controller, or in the autoloader.php
Code:
$autoload['helper']= array('url');
#7

[eluser]raimon[/eluser]
And why CI is putting index.php in the url ?
Code:
http://127.0.0.1/igni/index.php/user/index.php/user/validatelogin

if I remember well, my default page/controller is welcome.php and I'm not using index.php in anyplace ...

I'm going to try the base_url() and see ...


thanks,


r.
#8

[eluser]raimon[/eluser]
If I change this into:
Code:
$config['base_url']    = "http://127.0.0.1/igni/";

and in the form_open():
Code:
&lt;?= form_open(base_url().'user/validatelogin/'); ?&gt;


If I write:
Code:
http://127.0.0.1/igni/
=> login form ok

after submitting the form, I get an 404 and the url is:
Code:
http://127.0.0.1/igni/index.php/http://127.0.0.1/igni/user/validatelogin


for the index.php, I see that there is:
Code:
$config['index_page'] = "index.php";

Maybe CI puts it because some missing controller/parameter ?


thanks again ...

regards,

r.
#9

[eluser]gtech[/eluser]
sorry for the misinfo I shall now stick my fingers in a deep fat fryer so I dont do it again!

I read my code and I use somthing like the following

Code:
&lt;?=form_open('../index.php/user/validatelogin','','');?&gt;

or

Code:
&lt;?=form_open('controller/method');?&gt;
[url="http://ellislab.com/forums/viewthread/58293/"]^ cut and pasted from 58293[/url]

this thread should also help you

[url="http://ellislab.com/forums/viewthread/65085/"] (see thread for remove index.php)[/url]

you need to create a .htaccess file to remove the index.php if you search the forums this has been posted before.
#10

[eluser]raimon[/eluser]
Hello again ...

If I use in my view as you mention, I get the famous index.php in the url ...

Code:
&lt;?=form_open('../index.php/user/validatelogin','','');?&gt;;


my config/routes.php has only this:
Code:
$route['default_controller'] = "welcome"; // "welcome";
$route['scaffolding_trigger'] = "";


where are you using this, in a controller, view ?
and what's the purpose of the index.php in the main address?
Code:
&lt;?=form_open('../index.php/user/validatelogin','','');?&gt;

and, if I remove the index.php as this:
Code:
$config['index_page'] = //"index.php";


my new url for the form action is:
Code:
hola&lt;form action="AUTO/AUTO/user/validatelogin" method="post"&gt;


I'm reading some posts about .htaccess, but I don't understand why I have to change some prefs from the web server for this, maybe I have to re-read again the introduction to code igniter ...

thanks for your time !

r.




Theme © iAndrew 2016 - Forum software by © MyBB