Quarismo
Quarismo

Reputation: 57

CodeIgniter, Requested page was not found

I'm developing a web application in CodeIgniter, having a problem with the '404 page not found error'. Currently I have a login page, on which both the submit button and the link to the registration page are displaying the error. I've posted the code from the login page, controller and .htaccess below. For the login form, the error occurs always, regardless of whether the correct or incorrect login details are used.

Controller:

<?php
    class Main extends CI_Controller {

        public function __construct() { 
                parent::__construct();
                $this->load->model('system');
                $this->load->helper('url_helper');
            }

        public function index() {
            $this->login();
        }

        public function login() {
            $this->load->helper('form');
            $this->load->library('form_validation');

            $data['title'] = "Login";

            $this->form_validation->set_rules('','','');
            $this->form_validation->set_rules('','','');

            if($this->form_validation->run() === FALSE) {
                $this->load->view('login', $data);
            } else {
                $this->authenticateuser();
            }
        }

        public function authenticateuser() {
            $username = $this->input->post('idNumber');
            $password = md5($this->input->post('passWd'));

            $query = $this->db->query("select * from users where idNumber='".$username."' and passWd='$password'");
            $row = $query->num_rows();

            if($row) {
                $this->session->set_userdata(array('username' => $username));
                $sessionID = $this->session->userdata('username');
                $data['title'] = 'Dashboard';

                $this->load->view('dashboard', $data);
            } else {
                $data['error'] = 'Invalid Login Details';
                $data['title'] = 'Login';

                $this->load->view('login', $data);
            }
        }

        public function logout() {
            $this->session->unset_userdata('username');
            redirect('login');
        }

        // handles register page
        public function register() {
            $this->load->view('register');

            if($this->input->post('register')) {
                $username=$this->input->post('userid');
                $password=md5($this->input->post('pass'));

                $this->System->registeruser($username, $password);
                echo "User Registration Complete";
            }
        }
    }
?>

Login:

<html>
    <head>
        <title>Login form</title>
    </head>

    <body>
        <?php
            echo form_open('Main/authenticateuser');
            echo validation_errors();

            echo "<p>Username: ";
            echo form_input('username', $this->input->post('username'));
            echo "</p>";

            echo "<p>Password: ";
            echo form_password('password');
            echo "</p>";

            echo form_submit('login', 'Login');
            echo form_close();

        ?>

        <p><a href="regsiter">Register</a></p>
    </body>
</html>

.htaccess:

Options +FollowSymlinks -Indexes
RewriteEngine on

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

Upvotes: 0

Views: 57

Answers (1)

Boominathan Elango
Boominathan Elango

Reputation: 1191

Change

<p><a href="regsiter">Register</a></p>

into

<p><a href="<?php echo base_url();?>main/register">Register</a></p>

and change your htaccess into

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

Upvotes: 1

Related Questions