0

I wonder if anyone can help me??? I'm using CodeIgniter to create a small Login Screen. However, every time I call the function to validate the details using the CodeIgniter form helper. A 404 error keeps showing stating that CodeIgniter can't find the URL. My code for the 'View' file looks like:

<!doctype html>
<html>
<head>
    <title>CodeIgniter Prototype</title>

    <!-- CSS/LESS Code Links -->
    <link rel = "stylesheet" href = "<?php echo base_url();?>css/style.css" type = "text/css"/>
</head>

<body>
    <div class = "login_wrapper">
        <h1>ONESG OneInvoice Exporter</h1>
        <?php
            echo form_open('login/check_login');
            echo form_input('username', '', 'placeholder = "Enter Username"');
            echo form_password('password', '', 'placeholder = "Enter Password"');
            echo form_submit('submit', 'Login');
            echo form_close();
        ?>
    </div>
</body>
</html>

My Controller Code Looks Like:

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

class Login extends CI_Controller {

    public function index() {
        $this->load->view('login_form');
    }

    public function check_login() {
        $this->load->model('login_model');
        $query = $this->login_model->validate();

        if ($query) {
            $data = array (
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );

            $this->sessions->set_userdata($data);
            redirect('site/members_area');
        }

        else {
            $this->index();
        }
    }

}
13
  • please post your controller code Commented Jul 22, 2013 at 19:15
  • <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Login extends CI_Controller { public function index() { $this->load->view('login_form'); } public function check_login() { $this->load->model('login_model'); $query = $this->login_model->validate(); if ($query) { $data = array ( 'username' => $this->input->post('username'), 'is_logged_in' => true ); $this->sessions->set_userdata($data); redirect('site/members_area'); } else { $this->index(); } } } Commented Jul 22, 2013 at 19:20
  • Could you please edit your question and put it there with formating. :) Commented Jul 22, 2013 at 19:24
  • do you have index.php in your url ?? Commented Jul 22, 2013 at 19:26
  • So after accessing yoururl.com/index.php/Login you get 404 ? Commented Jul 22, 2013 at 19:27

3 Answers 3

2

Check your folder structure whether you have .htaccess file. if not add file name called .htaccess and add following code to file

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Add this in .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Then in routes.php in config add

$route["members_area/(.*)"] = 'site/members_area/$1';

Comments

0

add .htaccess file

 <IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.