Problem with Login form using Codeigniter

Hi, I just started studying codeigniter and I am now creating a login form. I got the code from external sources and now I’m getting an error with the code. Here’s the error:

The page you requested was not found.

technically, the page I am requesting cannot be found. here’s the snippet of my VIEW:

<div class="modal-body">
									<?php echo validation_errors(); ?>
									<?php echo form_open('verifylogin'); ?>
									<form method="POST">
										<div class="form-group">
											<label for="Username">Username</label>
											<input type="text" class="form-control" id="exampleInputEmail1" placeholder="Username" name="user">
										</div>
										<div class="form-group">
											<label for="Password">Password</label>
											<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="pass">
										</div>
										<div class="checkbox">
											<label>
											  <input type="checkbox"> Remember Me
											</label>
										</div>
										<button type="submit" class="btn btn-default" value="Login">Submit</button>
									</form>
								</div>

what causing the error is this `<?php echo form_open('verifylogin'); ?>

`When I patients login button at the sidebar section a modal form will come out. When you click the submit it redirects to verifylogin controller.

This is the verifylogin .php code located in my controller:

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

class VerifyLogin extends CI_Controller {

function __construct()
{
parent::__construct();
$this->load->model(‘user’,‘’,TRUE);
}

function index( $page = ‘home’ )
{
if ( ! file_exists(APPPATH.‘/views/pages/’.$page.‘.php’)){
show_404();
}
//This method will have the credentials validation
$this->load->library(‘form_validation’);

$this->form_validation->set_rules(‘user’, ‘Username’, ‘trim|required|xss_clean’);
$this->form_validation->set_rules(‘pass’, ‘Password’, ‘trim|required|xss_clean|callback_check_database’);

if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->load->view(‘pages/’.$page);
}
else
{
//Go to private area
redirect(‘patient’, ‘refresh’);
}

}

function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post(‘username’);

//query the database
$result = $this->user->login($username, $password);

if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
‘id’ => $row->id,
‘username’ => $row->username
);
$this->session->set_userdata(‘logged_in’, $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message(‘check_database’, ‘Invalid username or password’);
return false;
}
}
}

What I want to achieve is when successful login, my hidden page would appear on the menu. Here’s the site: http://ospar.netau.net/

Thank you

I would hesitate a guess and think that “verifylogin” has not been declared on the ./config/router.php

Try this:


$route["verifylogin'"]     = "verifylogin/index";

Also in your ./config.php file set

$config['log_threshold'] = 4;

and check the logfile.

[ot]I usually change the following ./config setting to make it easier to monitor

$config['log_path'] = APPPATH; // ORIGINAL PATH ''; 

[/ot]

Hi, thank you for helping me out. So just to share, this is my current routes.php:

    $route['default_controller'] = 'pages/view';
$route['authorized/(:any)'] = 'elogin/view/$1';
$route['(:any)'] = 'pages/view/$1';


$route['404_override'] = '';

so I should add verifylogin.php in the routes? Forgive me, I’m just a newbie in CI. I thought VIEWS is the thing to be routed. So even the file in CONTROLLERS folder can be routed?

Hi, I was able to solve my problem by declaring “verifylogin” in routes.php. Thank you soooooo much! You save me. :smile:

1 Like

Hi, why does it stay in verifylogin page after success or unsuccessful login? Can you try to access it. Username: bob, Password: supersecret

My homepage:
[http://ospar.netau.net/][1]

Thanks
[1]: http://ospar.netau.net/

I tried logging in with “bob” and “supersecret” without success. The message returned was “Error! Username or Password is Incorrect!” and the option to try and login again, which is what I would expect.

I would try Googling for “CodeIgniter Tutorial login”. Then try one as a standalone and make sure it does what you want it to do. After extensive testing try using the script on your site.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.