0

看看这段代码,我一直收到错误 404 The requested URL not found The requested URL /Surway_Test/verifylogin was not found on this server。不知道有什么问题。

谁能帮忙?这是我的代码

控制器:验证登录.php

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

class Verifylogin extends CI_Controller {

 function index()
 {
   //This method will have the credentials validation
   $this->load->model('user','',TRUE);  
   $this->load->library('form_validation');

   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', '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('login_view');
   }
   else
   {
     //Go to private area
     redirect('home', '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;
   }
 }
}
?>

主页.php

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI

class Home extends CI_Controller {

 function index()
 {
   if($this->session->userdata('logged_in'))
   {
     $session_data = $this->session->userdata('logged_in');
     $data['username'] = $session_data['username'];
     $this->load->view('home_view', $data);
   }
   else
   {
     //If no session, redirect to login page
     redirect('login', 'refresh');
   }
 }

 function logout()
 {
   $this->session->unset_userdata('logged_in');
   session_destroy();
   //redirect('home', 'refresh');
 }

}

?>

型号:user.php

<?php
Class User extends CI_Model
{
 function login($username, $password)
 {
   $data['main_content'] = 'login_view';
   $this->load->view('includes/template', $data);
   $this->db->select('id, username, password');
   $this->db->from('membership');
   $this->db->where('username', $username);
   $this->db->where('password', md5($password));
   $this->db->limit(1);

   $query = $this->db->get();

   if($query->num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }
}
?>

查看:login_view.php

<html>
 <head>
   <title>Login</title>
 </head>
 <body>
   <h1>Login</h1>
   <?php echo validation_errors(); ?>
   <?php echo form_open('verifylogin'); ?>
     <label for="username">Username:</label>
     <input type="text" size="20" id="username" name="username"/>
     <br/>
     <label for="password">Password:</label>
     <input type="password" size="20" id="passowrd" name="password"/>
     <br/>
     <input type="submit" value="Login"/>
   </form>
 </body>
4

1 回答 1

0

小修复,您必须像这样以小写字母开头控制器名称...

<?php echo form_open('verifyLogin'); ?>
    <label for="username">Username:</label>
    <input type="text" size="20" id="username" name="username" />
    <br/>
    <label for="password">Password:</label>
    <input type="password" size="20" id="passowrd" name="password" />
    <br/>
    <input type="submit" value="Login" />
</form>
于 2013-02-25T07:59:50.947 回答