1

I am trying to access my page 'login', and I'm using Codeingiter.

I'm using TAL php too, for templates.

I just defined my routes like this:

$route['default_controller'] = "site";
$route['404_override']       = '';

$route['login']   = 'login';
$route['signup']  = 'login';
$route['success'] = 'login';

And here is my 'login' controller :

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

class Login extends CI_controller{

public function __construct(){

    parent::__construct();
    $this->tal->setOutputMode(PHPTAL::HTML5);
        if($this->session->userdata('loggedIn') == true){
            $this->tal->template = 'admin';
            $this->tal->login = true;   
        }else{
            $this->tal->template = 'main';
            $this->tal->login = false;              
        }
    $this->load->model('membership_model');
}

public function index(){

    $requestPage = $this->uri->segment(1);

    switch($requestPage){
        case 'login':
            $this->tal->title = 'Connexion';
            $this->tal->display('login.php');

        break;
        case 'signup':
            $this->tal->title = 'Inscription';
            $this->tal->display('signup.php');
            $this->createMember();  
        break;
        case 'success':
            $this->tal->title = 'Inscription validée!';
            $this->tal->display('messagePage/signupSuccess.php');
        break;
    }
}

function validateCredentials(){

    $query = $this->membership_model->validate();
        if($query){
            $userdata = array(
                'username' => $this->input->post('username'),
                'password' => md5($this->input->post('password')),
                'loggedIn' => true
            );
            $this->session->set_userdata($userdata);
            redirect('backoffice/profile/#');       
        }
    $this->index();
}

function createMember(){

    $this->load->library('form_validation');
    $this->form_validation->set_rules('name', 'Nom', 'trim|required');
    $this->form_validation->set_rules('forename', 'Prénom', 'trim|required');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('adress', 'Adresse', 'trim|required');
    $this->form_validation->set_rules('zipcode', 'Code Postal', 'trim|is_natural|required');
    $this->form_validation->set_rules('city', 'Ville', 'trim|required');
    $this->form_validation->set_rules('country', 'Pays', 'trim|required');
    $this->form_validation->set_rules('username', 'Pseudo', 'trim|required|callback_usernameCheck');
    $this->form_validation->set_rules('password', 'Mot de passe', 'trim|required|min_length[4]|max_length[32]');
    $this->form_validation->set_rules('password2', 'Confirmation du mot de passe', 'trim|required|matches[password]');
    $this->form_validation->set_rules('captcha', 'Captcha');

    $data = array(
        'firstname'      => $this->input->post('name'),
        'forename'       => $this->input->post('forename'),
        'username'       => $this->input->post('username'),
        'email'          => $this->input->post('email'),
        'adress'         => $this->input->post('adress'),
        'zipcode'        => $this->input->post('zipcode'),
        'city'           => $this->input->post('city'),
        'country'        => $this->input->post('country'),
        'password'       => $this->input->post('password'),
        'passwordHashed' => md5($this->input->post('password'))
    );

    if($this->form_validation->run() == false){}
    else{
        $result = $this->membership_model->usernameCheck();
        var_dump($result);
        switch($result){
            case false:echo 'false';
                $this->form_validation->set_message('', 'Désolé mais ce nom d\'utilisateur et / ou cet email sont déjà pris');
            break;
            case true:echo 'true';
                $this->membership_model->createMember($data);
                redirect('success');
            break;
        }
    }
}

function logout(){  
    $this->session->sess_destroy();  
    redirect('/'); 
}

}//this ends class

My local URL is : http://localhost/dist.

And when I try to access it, with the URL http://localhost/dist/login, I just get '404 Page Not Found : The page you requested was not found.'

I don't understand why. All is ready.

Expedito
  • 7,771
  • 5
  • 30
  • 43
Lilrom
  • 15
  • 1
  • 7

2 Answers2

1

Try accessing the url http://localhost/dist/index.php/login. It doesn't appear that you have removed the index.php in the config file. Here is how to do that.

Community
  • 1
  • 1
brightintro
  • 1,016
  • 1
  • 11
  • 16
  • I'm trying this url, and that's right. But i have in my .htaccess, on the folder application : `RewriteEngine on RewriteBase / # Hide the application and system directories by redirecting the request to index.php RewriteRule ^(application|system) index.php/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L]` But, i've the 404 error if i try to access the url `http://localhost/dist/login`. – Lilrom Apr 23 '13 at 13:29
  • In the `application/config/config.php` file did you change the `$config['index_page'] = '';` to an empty string? – brightintro Apr 23 '13 at 13:32
  • Yes! In my config.php files, i have $config['index_page'] = ''; So, that's why i don't understand. – Lilrom Apr 23 '13 at 13:32
  • try changing `RewriteBase /` to `RewriteBase /dist/`. Since your codeigniter application is located within a folder, you need to specify that in the .htaccess file – brightintro Apr 23 '13 at 13:47
  • I've just try to change `RewriteBase /` to `RewriteBase /dist/` and i have try to change too : `RewriteRule ^(.*)$ index.php/$1 [L]` to `RewriteRule ^(.*)$ /DIST/index.php/$1 [L]` but all are not good. `www/DIST/application` : my folder application is just on my "DIST" folder, which is on www localhost folder. – Lilrom Apr 23 '13 at 13:52
  • Oh ok, i've found. I had an other .htaccess on my DIST folder, that's why this is not working. The problem is solved, thank's for your answers. – Lilrom Apr 23 '13 at 13:55
0

Have you tried debugging it?
If you don't have any routes defined, do you still get the 404 error?
I would bet that the issue is because you're routing a path to itself, but I don't know for sure.

Take out all of the routes and make sure that the path works. Then, add one at a time until it stops working.

Trenton Trama
  • 4,890
  • 1
  • 22
  • 27
  • I've just found the problem, with the answer of ekims. I juste have to write the url : http://localhost/dist/index.php/login, maybe because i've not remove the index.php on the .htaccess. Thank's for your answer. – Lilrom Apr 23 '13 at 13:23